Skip to content

Commit

Permalink
fix Issue 17380 - [REG 2.074.0] Compiler segfaults on undefined symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jul 5, 2017
1 parent de3cb1a commit a583f97
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/ddmd/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,23 @@ extern (C++) abstract class Type : RootObject
*/
final Expression noMember(Scope* sc, Expression e, Identifier ident, int flag)
{
//printf("Type.noMember(e: %s ident: %s flag: %d)\n", e.toChars(), ident.toChars(), flag);

static __gshared int nest; // https://issues.dlang.org/show_bug.cgi?id=17380

static Expression returnExp(Expression e)
{
--nest;
return e;
}

if (++nest > 500)
{
.error(e.loc, "cannot resolve identifier `%`", ident.toChars());
return returnExp(flag & 1 ? null : new ErrorExp());
}


assert(ty == Tstruct || ty == Tclass);
auto sym = toDsymbol(sc).isAggregateDeclaration();
assert(sym);
Expand Down Expand Up @@ -2744,7 +2761,7 @@ extern (C++) abstract class Type : RootObject
*/
e = build_overload(e.loc, sc, e, null, fd);
e = new DotIdExp(e.loc, e, ident);
return e.semantic(sc);
return returnExp(e.semantic(sc));
}

/* Look for overloaded opDispatch to see if we should forward request
Expand All @@ -2759,7 +2776,7 @@ extern (C++) abstract class Type : RootObject
if (!td)
{
fd.error("must be a template opDispatch(string s), not a %s", fd.kind());
return new ErrorExp();
return returnExp(new ErrorExp());
}
auto se = new StringExp(e.loc, cast(char*)ident.toChars());
auto tiargs = new Objects();
Expand All @@ -2775,7 +2792,7 @@ extern (C++) abstract class Type : RootObject
e = dti.semanticY(sc, 0);
if (flag & 1 && global.endGagging(errors))
e = null;
return e;
return returnExp(e);
}

/* See if we should forward to the alias this.
Expand All @@ -2787,10 +2804,10 @@ extern (C++) abstract class Type : RootObject
*/
e = resolveAliasThis(sc, e);
auto die = new DotIdExp(e.loc, e, ident);
return die.semanticY(sc, flag & 1);
return returnExp(die.semanticY(sc, flag & 1));
}
}
return Type.dotExp(sc, e, ident, flag);
return returnExp(Type.dotExp(sc, e, ident, flag));
}

Expression defaultInit(Loc loc = Loc())
Expand Down
21 changes: 21 additions & 0 deletions test/fail_compilation/test17380.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* TEST_OUTPUT:
---
fail_compilation/test17380.d(12): Error: undefined identifier `ThisTypeDoesNotExistsAndCrahesTheCompiler`
---
* https://issues.dlang.org/show_bug.cgi?id=17380
*/

struct Int128
{
Uint128 opCast()
{
return ThisTypeDoesNotExistsAndCrahesTheCompiler;
}
alias opCast this;
}

struct Uint128
{
Int128 opCast() { return Int128.init; }
alias opCast this;
}

0 comments on commit a583f97

Please sign in to comment.