Skip to content

Commit

Permalink
Fix issue 17918 - Stop if the late semantic pass fails
Browse files Browse the repository at this point in the history
No matter what the outcome of finishVtbl was the old code kept building
the rest of the class. If the late semantic pass over the
FunctionDeclaration fails we should abort the codegen phase instead of
going on.
  • Loading branch information
LemonBoy committed Mar 28, 2018
1 parent 2e21d07 commit 352b709
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/dmd/toobj.d
Expand Up @@ -350,7 +350,13 @@ void toObjFile(Dsymbol ds, bool multiobj)
member.accept(this);
}

finishVtbl(cd);
// If something goes wrong during this pass don't bother with the
// rest as we may have incomplete info
// https://issues.dlang.org/show_bug.cgi?id=17918
if (!finishVtbl(cd))
{
return;
}

// Generate C symbols
toSymbol(cd);
Expand Down Expand Up @@ -1374,10 +1380,12 @@ void toObjFile(Dsymbol ds, bool multiobj)

/*********************************
* Finish semantic analysis of functions in vtbl[],
* check vtbl[] for errors.
* check vtbl[] for errors and returns false if it does.
*/
private void finishVtbl(ClassDeclaration cd)
private bool finishVtbl(ClassDeclaration cd)
{
bool hasError = false;

foreach (i; cd.vtblOffset() .. cd.vtbl.dim)
{
FuncDeclaration fd = cd.vtbl[i].isFuncDeclaration();
Expand All @@ -1390,7 +1398,10 @@ private void finishVtbl(ClassDeclaration cd)
}
// Ensure function has a return value
// https://issues.dlang.org/show_bug.cgi?id=4869
fd.functionSemantic();
if (!fd.functionSemantic())
{
hasError = true;
}

if (!cd.isFuncHidden(fd) || fd.isFuture())
{
Expand Down Expand Up @@ -1426,10 +1437,15 @@ private void finishVtbl(ClassDeclaration cd)
fd.toChars());
}
else
{
cd.error("use of `%s` is hidden by `%s`", fd.toPrettyChars(), cd.toChars());
}
hasError = true;
break;
}
}

return !hasError;
}


Expand Down
11 changes: 11 additions & 0 deletions test/fail_compilation/b17918.d
@@ -0,0 +1,11 @@
/*
TEST_OUTPUT:
---
fail_compilation/imports/b17918a.d(7): Error: undefined identifier `_listMap`
---
*/
import imports.b17918a;

class Derived : Base
{
}
9 changes: 9 additions & 0 deletions test/fail_compilation/imports/b17918a.d
@@ -0,0 +1,9 @@
module imports.b17918a;

class Base
{
auto byNode()
{
return _listMap;
}
}

0 comments on commit 352b709

Please sign in to comment.