Permalink
Browse files

fix Issue 9361 - Nasty bug and/or error message for template constain…

…ts using this

Add test cases
  • Loading branch information...
9rnsr committed Jan 23, 2013
1 parent b950009 commit d31dd28886a832b077b013c62a885fb02a6ed124
Showing with 70 additions and 0 deletions.
  1. +49 −0 test/fail_compilation/ice6538.d
  2. +21 −0 test/runnable/template9.d
@@ -41,3 +41,52 @@ void test6538b()
bar(42, 86);
}
+/**************************************/
+// 9361
+
+template Sym(alias A)
+{
+ enum Sym = true;
+}
+
+/*
+TEST_OUTPUT:
+---
+fail_compilation/ice6538.d(63): Error: cannot take a not yet instantiated symbol 'this' inside template constraint
+fail_compilation/ice6538.d(69): Error: template ice6538.S.foo does not match any function template declaration. Candidates are:
+fail_compilation/ice6538.d(63): ice6538.S.foo()() if (Sym!(this))
+fail_compilation/ice6538.d(69): Error: template ice6538.S.foo()() if (Sym!(this)) cannot deduce template function from argument types !()()
+---
+*/
+struct S
+{
+ void foo()() if (Sym!(this)) {}
+ void bar()() { static assert(Sym!(this)); } // OK
+}
+void test9361a()
+{
+ S s;
+ s.foo(); // fail
+ s.bar(); // OK
+}
+
+/*
+TEST_OUTPUT:
+---
+fail_compilation/ice6538.d(85): Error: cannot take a not yet instantiated symbol 'super' inside template constraint
+fail_compilation/ice6538.d(90): Error: template ice6538.D.foo does not match any function template declaration. Candidates are:
+fail_compilation/ice6538.d(85): ice6538.D.foo()() if (Sym!(super))
+fail_compilation/ice6538.d(90): Error: template ice6538.D.foo()() if (Sym!(super)) cannot deduce template function from argument types !()()
+---
+*/
+class C {}
+class D : C
+{
+ void foo()() if (Sym!(super)) {}
+}
+void test9361b()
+{
+ auto d = new D();
+ d.foo();
+}
+
View
@@ -1917,6 +1917,27 @@ void test9266()
Bar9266!() a, b;
}
+/**********************************/
+// 9361
+
+struct Unit9361(A)
+{
+ void butPleaseDontUseMe()()
+ if (is(unitType9361!((this)))) // !
+ {}
+
+}
+template isUnit9361(alias T) if ( is(T)) {}
+template isUnit9361(alias T) if (!is(T)) {}
+
+template unitType9361(alias T) if (isUnit9361!T) {}
+
+void test9361()
+{
+ Unit9361!int u;
+ static assert(!__traits(compiles, u.butPleaseDontUseMe())); // crashes
+}
+
/**********************************/
int main()

0 comments on commit d31dd28

Please sign in to comment.