Skip to content

Commit 9921b6c

Browse files
authored
Merge pull request #11145 from MoonlightSentinel/unit-seg
Fix Issue 20626 - ICE when using typeof of unittest symbol without -u… merged-on-behalf-of: Mathias LANG <pro.mathias.lang@gmail.com>
2 parents 89dcfda + 71ce029 commit 9921b6c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/dmd/typesem.d

+4-1
Original file line numberDiff line numberDiff line change
@@ -2896,7 +2896,10 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds
28962896
if (auto f = mt.exp.op == TOK.variable ? (cast( VarExp)mt.exp).var.isFuncDeclaration()
28972897
: mt.exp.op == TOK.dotVariable ? (cast(DotVarExp)mt.exp).var.isFuncDeclaration() : null)
28982898
{
2899-
if (f.checkForwardRef(loc))
2899+
// f might be a unittest declaration which is incomplete when compiled
2900+
// without -unittest. That causes a segfault in checkForwardRef, see
2901+
// https://issues.dlang.org/show_bug.cgi?id=20626
2902+
if ((!f.isUnitTestDeclaration() || global.params.useUnitTests) && f.checkForwardRef(loc))
29002903
goto Lerr;
29012904
}
29022905
if (auto f = isFuncAddress(mt.exp))

test/fail_compilation/test20626.d

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
REQUIRED_ARGS: -check=invariant=off
3+
TEST_OUTPUT:
4+
----
5+
fail_compilation/test20626.d(2): Error: expression `__unittest_L1_C1` has no type
6+
_error_
7+
const void()
8+
----
9+
10+
https://issues.dlang.org/show_bug.cgi?id=20626
11+
*/
12+
13+
#line 1
14+
unittest {}
15+
pragma(msg, typeof(__unittest_L1_C1));
16+
17+
struct S
18+
{
19+
invariant {}
20+
}
21+
22+
pragma(msg, typeof(S.init.__invariant1));

0 commit comments

Comments
 (0)