Skip to content

Commit

Permalink
Merge pull request #1336 from AndrejMitrovic/Fix8928
Browse files Browse the repository at this point in the history
[diag] Issue 8928 - Improve error message with implicitly generated constructor
  • Loading branch information
WalterBright committed Dec 9, 2012
2 parents ce7f3d8 + 6a48402 commit 4cc63a0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/class.c
Expand Up @@ -735,6 +735,7 @@ void ClassDeclaration::semantic(Scope *sc)
//printf("Creating default this(){} for class %s\n", toChars());
Type *tf = new TypeFunction(NULL, NULL, 0, LINKd, 0);
CtorDeclaration *ctor = new CtorDeclaration(loc, 0, 0, tf);
ctor->isImplicit = true;
ctor->fbody = new CompoundStatement(0, new Statements());
members->push(ctor);
ctor->addMember(sc, this, 1);
Expand Down
1 change: 1 addition & 0 deletions src/declaration.h
Expand Up @@ -755,6 +755,7 @@ struct CtorDeclaration : FuncDeclaration
int isVirtual();
int addPreInvariant();
int addPostInvariant();
bool isImplicit; // implicitly generated ctor

CtorDeclaration *isCtorDeclaration() { return this; }
};
Expand Down
6 changes: 5 additions & 1 deletion src/func.c
Expand Up @@ -1276,7 +1276,10 @@ void FuncDeclaration::semantic3(Scope *sc)

e = e->trySemantic(sc2);
if (!e)
error("no match for implicit super() call in constructor");
{
const char* impGen = ((CtorDeclaration*)this)->isImplicit ? "implicitly generated " : "";
error("no match for implicit super() call in %sconstructor", impGen);
}
else
{
Statement *s = new ExpStatement(0, e);
Expand Down Expand Up @@ -3352,6 +3355,7 @@ CtorDeclaration::CtorDeclaration(Loc loc, Loc endloc, StorageClass stc, Type *ty
: FuncDeclaration(loc, endloc, Id::ctor, stc, type)
{
//printf("CtorDeclaration(loc = %s) %s\n", loc.toChars(), toChars());
this->isImplicit = false;
}

Dsymbol *CtorDeclaration::syntaxCopy(Dsymbol *s)
Expand Down
21 changes: 21 additions & 0 deletions test/fail_compilation/diag8928.d
@@ -0,0 +1,21 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag8928.d(7): Error: constructor diag8928.Y.this no match for implicit super() call in constructor
fail_compilation/diag8928.d(10): Error: constructor diag8928.Z.this no match for implicit super() call in implicitly generated constructor
---
*/

#line 1
class X {
this(int n) {}
}

class Y : X
{
this() { }
}

class Z : X
{
}

0 comments on commit 4cc63a0

Please sign in to comment.