Skip to content

Commit

Permalink
Merge pull request #5368 from MartinNowak/fix15550
Browse files Browse the repository at this point in the history
fix Issue 15550 - compile error while testing template constraint
  • Loading branch information
andralex committed Jan 27, 2016
2 parents 8399e29 + 5fbc1b8 commit 682687b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/dinterpret.d
Expand Up @@ -710,6 +710,11 @@ extern (C++) Expression ctfeInterpret(Expression e)
{
if (e.op == TOKerror)
return e;
if (e.op == TOKscope && !e.type) // workaround Bugzilla 15239
{
e.error("cannot interpret %s at compile time", e.toChars());
return new ErrorExp();
}
assert(e.type); // Bugzilla 14642
//assert(e->type->ty != Terror); // FIXME
if (e.type.ty == Terror)
Expand Down
15 changes: 6 additions & 9 deletions src/expression.d
Expand Up @@ -5234,12 +5234,12 @@ extern (C++) final class ScopeExp : Expression
public:
ScopeDsymbol sds;

extern (D) this(Loc loc, ScopeDsymbol sds)
extern (D) this(Loc loc, ScopeDsymbol pkg)
{
super(loc, TOKscope, __traits(classInstanceSize, ScopeExp));
//printf("ScopeExp::ScopeExp(sds = '%s')\n", sds.toChars());
//printf("ScopeExp::ScopeExp(sds = '%s')\n", pkg->toChars());
//static int count; if (++count == 38) *(char*)0=0;
this.sds = sds;
this.sds = pkg;
}

override Expression syntaxCopy()
Expand All @@ -5253,8 +5253,8 @@ public:
{
printf("+ScopeExp::semantic(%p '%s')\n", this, toChars());
}
if (type)
return this;
//if (type == Type::tvoid)
// return this;

ScopeDsymbol sds2 = sds;
TemplateInstance ti = sds2.isTemplateInstance();
Expand Down Expand Up @@ -5294,9 +5294,6 @@ public:
return e.semantic(sc);
}
}
// ti is an instance which requires IFTI.
sds = ti;
type = Type.tvoid;
return this;
}
ti.semantic(sc);
Expand Down Expand Up @@ -8895,7 +8892,7 @@ public:
/* This recognizes:
* foo!(tiargs)(funcargs)
*/
if (e1.op == TOKscope)
if (e1.op == TOKscope && !e1.type)
{
ScopeExp se = cast(ScopeExp)e1;
TemplateInstance ti = se.sds.isTemplateInstance();
Expand Down
13 changes: 13 additions & 0 deletions test/compilable/test15550.d
@@ -0,0 +1,13 @@
struct Vector(T, int N)
{
void opDispatch(string, U)(U)
{
}

void baz(string, U)(U)
{
}
}

static assert(!is(typeof(Vector!(int, 2)._isMatrix)));
static assert(!is(typeof(Vector!(int, 2).baz!"_isMatrix")));
2 changes: 1 addition & 1 deletion test/fail_compilation/fail10481.d
Expand Up @@ -2,7 +2,7 @@
TEST_OUTPUT:
---
fail_compilation/fail10481.d(11): Error: undefined identifier 'T1', did you mean alias 'T0'?
fail_compilation/fail10481.d(15): Error: cannot infer type from template instance get!(A)
fail_compilation/fail10481.d(15): Error: cannot resolve type for get!(A)
---
*/

Expand Down
27 changes: 27 additions & 0 deletions test/fail_compilation/fail15550.d
@@ -0,0 +1,27 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail15550.d(25): Error: expression (foo!int) has no type
fail_compilation/fail15550.d(26): Error: expression (opDispatch!"_isMatrix") has no type
fail_compilation/fail15550.d(27): Error: expression (baz!"_isMatrix") has no type
---
*/

T foo(T, T2)(T2)
{
}

struct Vector
{
void opDispatch(string, U)(U)
{
}

void baz(string, U)(U)
{
}
}

alias T1 = typeof(foo!int);
alias T2 = typeof(Vector._isMatrix);
alias T3 = typeof(Vector.baz!"_isMatrix");

0 comments on commit 682687b

Please sign in to comment.