Skip to content

Commit

Permalink
Fix error propagation: TraitsExp should return ErrorExp if any errors…
Browse files Browse the repository at this point in the history
… happen
  • Loading branch information
9rnsr committed Aug 31, 2015
1 parent c4539ff commit 1e9744b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
42 changes: 21 additions & 21 deletions src/traits.d
Expand Up @@ -667,7 +667,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!t)
{
e.error("type expected as second argument of __traits %s instead of %s", e.ident.toChars(), o.toChars());
goto Lfalse;
return new ErrorExp();
}
Type tb = t.baseElemOf();
if (tb.ty == Tstruct && ((sd = cast(StructDeclaration)(cast(TypeStruct)tb).sym) !is null))
Expand Down Expand Up @@ -705,7 +705,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
goto Lfalse;
}
e.error("aggregate or function expected instead of '%s'", o.toChars());
goto Lfalse;
return new ErrorExp();
}
else if (e.ident == Id.isAbstractFunction)
{
Expand Down Expand Up @@ -768,7 +768,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!s || !s.ident)
{
e.error("argument %s has no identifier", o.toChars());
goto Lfalse;
return new ErrorExp();
}
id = s.ident;
}
Expand All @@ -791,7 +791,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
{
if (!isError(o))
e.error("argument %s has no protection", o.toChars());
goto Lfalse;
return new ErrorExp();
}
if (s._scope)
s.semantic(s._scope);
Expand All @@ -816,7 +816,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!s || s.isImport())
{
e.error("argument %s has no parent", o.toChars());
goto Lfalse;
return new ErrorExp();
}
if (FuncDeclaration f = s.isFuncDeclaration())
{
Expand Down Expand Up @@ -846,20 +846,20 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!ex)
{
e.error("expression expected as second argument of __traits %s", e.ident.toChars());
goto Lfalse;
return new ErrorExp();
}
ex = ex.ctfeInterpret();
StringExp se = ex.toStringExp();
if (!se || se.length() == 0)
{
e.error("string expected as second argument of __traits %s instead of %s", e.ident.toChars(), ex.toChars());
goto Lfalse;
return new ErrorExp();
}
se = se.toUTF8(sc);
if (se.sz != 1)
{
e.error("string must be chars");
goto Lfalse;
return new ErrorExp();
}
Identifier id = Identifier.idPool(cast(char*)se.string);
/* Prefer dsymbol, because it might need some runtime contexts.
Expand All @@ -877,7 +877,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
else
{
e.error("invalid first argument");
goto Lfalse;
return new ErrorExp();
}
if (e.ident == Id.hasMember)
{
Expand Down Expand Up @@ -952,7 +952,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!s || (cd = s.isClassDeclaration()) is null)
{
e.error("first argument is not a class");
goto Lfalse;
return new ErrorExp();
}
if (cd.sizeok == SIZEOKnone)
{
Expand All @@ -962,7 +962,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (cd.sizeok != SIZEOKdone)
{
e.error("%s %s is forward referenced", cd.kind(), cd.toChars());
goto Lfalse;
return new ErrorExp();
}
return new IntegerExp(e.loc, cd.structsize, Type.tsize_t);
}
Expand All @@ -976,7 +976,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!s || (ad = s.isAggregateDeclaration()) is null)
{
e.error("argument is not an aggregate type");
goto Lfalse;
return new ErrorExp();
}
auto exps = new Expressions();
if (ad.aliasthis)
Expand All @@ -1003,7 +1003,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
printf("t = %d %s\n", t.ty, t.toChars());
}
e.error("first argument is not a symbol");
goto Lfalse;
return new ErrorExp();
}
if (s.isImport())
{
Expand Down Expand Up @@ -1042,7 +1042,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!tf)
{
e.error("first argument is not a function");
goto Lfalse;
return new ErrorExp();
}
auto mods = new Expressions();
PushAttributes pa;
Expand All @@ -1061,7 +1061,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!s)
{
e.error("argument has no members");
goto Lfalse;
return new ErrorExp();
}
if (Import imp = s.isImport())
{
Expand All @@ -1072,7 +1072,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!sds || sds.isTemplateDeclaration())
{
e.error("%s %s has no members", s.kind(), s.toChars());
goto Lfalse;
return new ErrorExp();
}
// use a struct as local function
struct PushIdentsDg
Expand Down Expand Up @@ -1277,7 +1277,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!s)
{
e.error("argument %s to __traits(getUnitTests) must be a module or aggregate", o.toChars());
goto Lfalse;
return new ErrorExp();
}
Import imp = s.isImport();
if (imp) // Bugzilla 10990
Expand All @@ -1286,7 +1286,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!_scope)
{
e.error("argument %s to __traits(getUnitTests) must be a module or aggregate, not a %s", s.toChars(), s.kind());
goto Lfalse;
return new ErrorExp();
}
auto unitTests = new Expressions();
Dsymbols* symbols = _scope.members;
Expand All @@ -1309,7 +1309,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (!s || (fd = s.isFuncDeclaration()) is null)
{
e.error("first argument to __traits(getVirtualIndex) must be a function");
goto Lfalse;
return new ErrorExp();
}
fd = fd.toAliasFunc(); // Neccessary to support multiple overloads.
return new IntegerExp(e.loc, fd.vtblIndex, Type.tptrdiff_t);
Expand All @@ -1324,12 +1324,12 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
e.error("unrecognized trait '%s', did you mean '%s'?", e.ident.toChars(), sub);
else
e.error("unrecognized trait '%s'", e.ident.toChars());
goto Lfalse;
return new ErrorExp();
}
return null;
Ldimerror:
e.error("wrong number of arguments %d", cast(int)dim);
goto Lfalse;
return new ErrorExp();
Lfalse:
return new IntegerExp(e.loc, 0, Type.tbool);
Ltrue:
Expand Down
4 changes: 3 additions & 1 deletion test/fail_compilation/ice14844.d
Expand Up @@ -17,5 +17,7 @@ struct Typedef

void runUnitTestsImpl()
{
auto x = [__traits(allMembers, Typedef.opDispatch)];
foreach (x; __traits(allMembers, Typedef.opDispatch))
{
}
}

0 comments on commit 1e9744b

Please sign in to comment.