Skip to content

Commit

Permalink
merge #8940
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Nov 10, 2012
2 parents 8158595 + 33a4b46 commit b26f49c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/cast.c
Expand Up @@ -1755,6 +1755,10 @@ Expression *FuncExp::inferType(Type *to, int flag, TemplateParameters *tparams)

TemplateInstance *ti = new TemplateInstance(loc, td, tiargs);
e = (new ScopeExp(loc, ti))->semantic(td->scope);

// Reset inference target for the later re-semantic
fld->treq = NULL;

if (e->op == TOKfunction)
{ FuncExp *fe = (FuncExp *)e;
assert(fe->td == NULL);
Expand Down
24 changes: 24 additions & 0 deletions src/expression.c
Expand Up @@ -8389,6 +8389,30 @@ Expression *CallExp::semantic(Scope *sc)

if (ve->hasOverloads)
f = f->overloadResolve(loc, NULL, arguments, 2);
else
{
TypeFunction *tf = (TypeFunction *)f->type;
if (!tf->callMatch(NULL, arguments))
{
OutBuffer buf;

buf.writeByte('(');
if (arguments && arguments->dim)
{
HdrGenState hgs;

argExpTypesToCBuffer(&buf, arguments, &hgs);
}
buf.writeByte(')');

//printf("tf = %s, args = %s\n", tf->deco, (*arguments)[0]->type->deco);
::error(loc, "%s %s is not callable using argument types %s",
e1->toChars(), Parameter::argsTypesToChars(tf->parameters, tf->varargs),
buf.toChars());

return new ErrorExp();
}
}

if (f->needThis())
{
Expand Down
2 changes: 0 additions & 2 deletions src/template.c
Expand Up @@ -2152,8 +2152,6 @@ FuncDeclaration *TemplateDeclaration::deduceFunctionTemplate(Scope *sc, Loc loc,
fd_best = ti->toAlias()->isFuncDeclaration();
if (!fd_best)
goto Lerror;
if (!((TypeFunction*)fd_best->type)->callMatch(fd_best->needThis() && !fd_best->isCtorDeclaration() ? ethis : NULL, fargs))
goto Lerror;

if (FuncLiteralDeclaration *fld = fd_best->isFuncLiteralDeclaration())
{
Expand Down
22 changes: 22 additions & 0 deletions test/runnable/template9.d
Expand Up @@ -1549,6 +1549,27 @@ void test8976()
static assert(!is(typeof( h8976!()() )));
}

/****************************************/
// 8940

const int n8940; // or `immutable`
static this() { n8940 = 3; }

void f8940(T)(ref int val)
{
assert(val == 3);
++val;
}

static assert(!__traits(compiles, f8940!void(n8940))); // fails
void test8940()
{
assert(n8940 == 3);
static assert(!__traits(compiles, f8940!void(n8940)));
//assert(n8940 == 3); // may pass as compiler caches comparison result
//assert(n8940 != 4); // may pass but likely will fail
}

/**********************************/

int main()
Expand Down Expand Up @@ -1612,6 +1633,7 @@ int main()
test14();
test8129();
test8976();
test8940();

printf("Success\n");
return 0;
Expand Down

0 comments on commit b26f49c

Please sign in to comment.