Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 7572 - f.fn!(void) is not an lvalue #1868

Merged
merged 2 commits into from Apr 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 56 additions & 1 deletion src/expression.c
Expand Up @@ -299,6 +299,16 @@ Expression *resolvePropertiesX(Scope *sc, Expression *e)
tthis = NULL;
goto L1;
}
TemplateInstance *ti = s->isTemplateInstance();
if (ti && !ti->semanticRun)
{
//assert(ti->needsTypeInference(sc));
td = ti->tempdecl;
ti->semanticTiargs(sc);
tiargs = ti->tiargs;
tthis = NULL;
goto L1;
}
}
else if (e->op == TOKtemplate)
{
Expand Down Expand Up @@ -4473,6 +4483,20 @@ Expression *ScopeExp::semantic(Scope *sc)
if (ti && !ti->errors)
{
unsigned olderrs = global.errors;
if (ti->needsTypeInference(sc))
{
TemplateDeclaration *td = ti->tempdecl;
Dsymbol *p = td->toParent2();
FuncDeclaration *fdthis = hasThis(sc);
AggregateDeclaration *ad = p ? p->isAggregateDeclaration() : NULL;
if (fdthis && ad && isAggregate(fdthis->vthis->type) == ad &&
(td->scope->stc & STCstatic) == 0)
{
Expression *e = new DotTemplateInstanceExp(loc, new ThisExp(loc), ti->name, ti->tiargs);
return e->semantic(sc);
}
return this;
}
if (!ti->semanticRun)
ti->semantic(sc);
if (ti->inst)
Expand Down Expand Up @@ -7873,7 +7897,8 @@ Expression *CallExp::semantic(Scope *sc)
*/
tiargs = ti->tiargs;
tierror = ti; // for error reporting
e1 = new IdentifierExp(loc, ti->name);
assert(ti->tempdecl);
e1 = new TemplateExp(loc, ti->tempdecl);
}
else
{
Expand Down Expand Up @@ -8667,6 +8692,36 @@ Expression *AddrExp::semantic(Scope *sc)
if (e1->type == Type::terror)
return new ErrorExp();
int wasCond = e1->op == TOKquestion;
if (e1->op == TOKdotti)
{
DotTemplateInstanceExp* dti = (DotTemplateInstanceExp *)e1;
TemplateInstance *ti = dti->ti;
assert(!ti->semanticRun);
//assert(ti->needsTypeInference(sc));
ti->semantic(sc);
if (!ti->inst) // if template failed to expand
return new ErrorExp;
Dsymbol *s = ti->inst->toAlias();
FuncDeclaration *f = s->isFuncDeclaration();
assert(f);
e1 = new DotVarExp(e1->loc, dti->e1, f);
e1 = e1->semantic(sc);
}
else if (e1->op == TOKimport &&
((ScopeExp *)e1)->sds->isTemplateInstance())
{
TemplateInstance *ti = (TemplateInstance *)((ScopeExp *)e1)->sds;
assert(!ti->semanticRun);
//assert(ti->needsTypeInference(sc));
ti->semantic(sc);
if (!ti->inst) // if template failed to expand
return new ErrorExp;
Dsymbol *s = ti->inst->toAlias();
FuncDeclaration *f = s->isFuncDeclaration();
assert(f);
e1 = new VarExp(e1->loc, f);
e1 = e1->semantic(sc);
}
e1 = e1->toLvalue(sc, NULL);
if (e1->op == TOKerror)
return e1;
Expand Down
38 changes: 34 additions & 4 deletions test/runnable/template9.d
Expand Up @@ -392,16 +392,26 @@ static assert(is(typeof(bug4953(3))));
/**********************************/
// 5886 & 5393

struct K5886 {
void get1(this T)() const {
struct K5886
{
void get1(this T)() const
{
pragma(msg, T);
}
void get2(int N=4, this T)() const {
void get2(int N=4, this T)() const
{
pragma(msg, N, " ; ", T);
}
void test() const
{
get1; // OK
get2; // OK
get2!8; // NG
}
}

void test5886() {
void test5886()
{
K5886 km;
const(K5886) kc;
immutable(K5886) ki;
Expand Down Expand Up @@ -1166,6 +1176,25 @@ void test7563()
pragma(msg, typeof(test.test!(int)).stringof); // Error: expression (test.test!(int)) has no type
}

/**********************************/
// 7572

class F7572
{
Tr fn7572(Tr, T...)(T t) { return 1; }
}
Tr Fn7572(Tr, T...)(T t) { return 2; }

void test7572()
{
F7572 f = new F7572();
int delegate() dg = &f.fn7572!int;
assert(dg() == 1);

int function() fn = &Fn7572!int;
assert(fn() == 2);
}

/**********************************/
// 7580

Expand Down Expand Up @@ -2326,6 +2355,7 @@ int main()
test7359();
test7416();
test7563();
test7572();
test7580();
test7585();
test7671();
Expand Down