Skip to content

Commit

Permalink
Fix issue 15922: DMD segfault in functionParameters on invalid code
Browse files Browse the repository at this point in the history
`Dsymbol.errors` is used to indicate a symbol failed semantic analysis.
Currently, `FuncDeclaration.semantic3` fails if the parent has error,
so the body of aggregates that already have errors is not processed.
However, the code was only `return`ing and not setting `Dsymbol.errors`
to `true`, resulting in this error being unnoticed by `functionSemantic`.
  • Loading branch information
mathias-lang-sociomantic committed Apr 14, 2016
1 parent 72bfdf6 commit aa0df5c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/func.d
Expand Up @@ -1329,8 +1329,11 @@ public:
//printf("FuncDeclaration::semantic3(%s '%s', sc = %p)\n", kind(), toChars(), sc);
assert(0);
}
if (isError(parent))
if (errors || isError(parent))
{
errors = true;
return;
}
//printf("FuncDeclaration::semantic3('%s.%s', %p, sc = %p, loc = %s)\n", parent->toChars(), toChars(), this, sc, loc.toChars());
//fflush(stdout);
//printf("storage class = x%x %x\n", sc->stc, storage_class);
Expand Down
26 changes: 26 additions & 0 deletions test/fail_compilation/ice15922.d
@@ -0,0 +1,26 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice15922.d(12): Error: function ice15922.ValidSparseDataStore!int.ValidSparseDataStore.correctedInsert!false.correctedInsert has no return statement, but is expected to return a value of type int
fail_compilation/ice15922.d(10): Error: template instance ice15922.ValidSparseDataStore!int.ValidSparseDataStore.correctedInsert!false error instantiating
fail_compilation/ice15922.d(15): instantiated from here: ValidSparseDataStore!int
fail_compilation/ice15922.d(3): Error: need 'this' for 'insert' of type 'pure @nogc @safe int()'
fail_compilation/ice15922.d(15): Error: template instance ice15922.StorageAttributes!(ValidSparseDataStore!int) error instantiating
---
*/
#line 1
template StorageAttributes(Store)
{
enum hasInsertMethod = Store.insert;
enum hasFullSlice = Store.init[];
}
struct ValidSparseDataStore(DataT)
{
DataT insert()
{
correctedInsert!(false);
}
DataT correctedInsert(bool CorrectParents)() {}
auto opSlice() inout {}
}
alias BasicCubeT = StorageAttributes!(ValidSparseDataStore!int);

0 comments on commit aa0df5c

Please sign in to comment.