diff --git a/src/dmd/dinterpret.d b/src/dmd/dinterpret.d index e44b8cb43323..062548c7e845 100644 --- a/src/dmd/dinterpret.d +++ b/src/dmd/dinterpret.d @@ -71,6 +71,10 @@ public Expression ctfeInterpret(Expression e) case TOK.super_: case TOK.type: case TOK.typeid_: + case TOK.template_: // non-eponymous template/instance + case TOK.scope_: // ditto + case TOK.dotTemplateDeclaration: // ditto, e.e1 doesn't matter here + case TOK.dot: // ditto if (e.type.ty == Terror) return ErrorExp.get(); goto case TOK.error; diff --git a/test/compilable/interpret5.d b/test/compilable/interpret5.d new file mode 100644 index 000000000000..ce13a5ab182d --- /dev/null +++ b/test/compilable/interpret5.d @@ -0,0 +1,30 @@ +// https://issues.dlang.org/show_bug.cgi?id=21927 +/* +TEST_OUTPUT: +--- +T1(Args...) +T1!() +T2(Args2...) +T2!() +this.T2(Args2...) +this.T2!() +--- +*/ +template T1(Args...) {} + +pragma(msg, T1); // TOK.template_ +pragma(msg, T1!()); // TOK.scope_ + +struct S +{ + template T2(Args2...) {} + + pragma(msg, S.T2); // TOK.template_ + pragma(msg, S.T2!()); // TOK.scope_ + + void fun() + { + pragma(msg, this.T2); // TOK.dotTemplateDeclaration + pragma(msg, this.T2!()); // TOK.dot + } +} diff --git a/test/fail_compilation/test21927.d b/test/fail_compilation/test21927.d new file mode 100644 index 000000000000..66c247be00d4 --- /dev/null +++ b/test/fail_compilation/test21927.d @@ -0,0 +1,22 @@ +// https://issues.dlang.org/show_bug.cgi?id=21927 +/* +TEST_OUTPUT: +--- +fail_compilation/test21927.d(19): Error: invalid `foreach` aggregate `this.T2(Args2...)` +fail_compilation/test21927.d(19): Error: invalid `foreach` aggregate `this.T2(Args2...)` +fail_compilation/test21927.d(20): Error: invalid `foreach` aggregate `this.T2!()` +fail_compilation/test21927.d(20): Error: invalid `foreach` aggregate `this.T2!()` +--- +*/ + +struct S +{ + template T2(Args2...) {} + + void fun() + { + // original test case + static foreach (p; this.T2) {} // ICE + static foreach (p; this.T2!()) {} // ICE + } +}