Skip to content

Commit

Permalink
Merge pull request #3734 from 9rnsr/fix13082
Browse files Browse the repository at this point in the history
Issue 13082 - Spurious error message with failed call to class ctor
  • Loading branch information
WalterBright authored and 9rnsr committed Jul 16, 2014
1 parent d30cd00 commit fb2c3b6
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 @@ -4878,12 +4878,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 @@ -4920,7 +4918,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 @@ -4983,12 +4981,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 fb2c3b6

Please sign in to comment.