Skip to content

Commit

Permalink
fix Issue 13082 - Spurious error message with failed call to class ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jul 11, 2014
1 parent 49f0db5 commit 320636d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/expression.c
Expand Up @@ -4869,12 +4869,10 @@ Expression *NewExp::semantic(Scope *sc)
goto Lerr;
}

FuncDeclaration *f = NULL;
if (cd->ctor)
f = resolveFuncCall(loc, sc, cd->ctor, NULL, tb, arguments, 0);
if (f)
{
if (f->errors)
FuncDeclaration *f = resolveFuncCall(loc, sc, cd->ctor, NULL, tb, arguments, 0);
if (!f || f->errors)
goto Lerr;
checkDeprecated(sc, f);
checkPurity(sc, f);
Expand Down Expand Up @@ -4911,7 +4909,7 @@ Expression *NewExp::semantic(Scope *sc)
newargs = new Expressions();
newargs->shift(e);

f = resolveFuncCall(loc, sc, cd->aggNew, NULL, tb, newargs);
FuncDeclaration *f = resolveFuncCall(loc, sc, cd->aggNew, NULL, tb, newargs);
if (!f || f->errors)
goto Lerr;
allocator = f->isNewDeclaration();
Expand Down Expand Up @@ -4974,12 +4972,10 @@ Expression *NewExp::semantic(Scope *sc)
}
}

FuncDeclaration *f = NULL;
if (sd->ctor && nargs)
f = resolveFuncCall(loc, sc, sd->ctor, NULL, tb, arguments, 0);
if (f)
{
if (f->errors)
FuncDeclaration *f = resolveFuncCall(loc, sc, sd->ctor, NULL, tb, arguments, 0);
if (!f || f->errors)
goto Lerr;
checkDeprecated(sc, f);
checkPurity(sc, f);
Expand Down
24 changes: 24 additions & 0 deletions test/fail_compilation/diag13082.d
@@ -0,0 +1,24 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag13082.d(22): Error: constructor diag13082.C.this (int a) is not callable using argument types (string)
fail_compilation/diag13082.d(23): Error: constructor diag13082.S.this (int a) is not callable using argument types (string)
---
*/

class C
{
this(int a) {}
}

struct S
{
this(int a) {}
}

void main()
{
string b;
auto c = new C(b);
auto s = new S(b);
}

0 comments on commit 320636d

Please sign in to comment.