Bug 6602 – Invalid template instantiations »leaked« by is(typeof())/__traits(compiles, …)/Type::trySemantic

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-09-04T21:29:00Z
Last change time
2011-09-05T16:50:52Z
Keywords
patch
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2011-09-04T21:29:25Z
Okay, turns out that the »collateral regression« the fix for bug 6220 caused in my code ([1]) really is a fundamental problem with how DMD handles template instantiations in the face of error gagging, in this case because is(typeof()) is used (same for __traits(compiles, …)): --- template A(T) { B!(T).Result result; } template B(U) { static assert(is(U == int)); alias bool Result; } pragma(msg, is(typeof(A!short))); --- The static assert in B!() should just cause is(typeof()) to evaluate to false, but B!short is also added to the module member list, causing compilation to fail because of !is(short == int). I am working on a fix, but need an issue number to reference. [1] https://github.com/D-Programming-Language/dmd/commit/60f4ec88decbcd00e765ab392bf8be8f526ed1ab#commitcomment-535706
Comment #1 by code — 2011-09-04T22:25:58Z
Wish I had discovered that earlier, not just from a bugzilla reference in the DMD source after I tracked the problem down: A very similar bug has already been reported, issue 4302. However, the fix proposed there (which got committed in e66a3a5) only hides the issue for static if conditionals, while it can also appear if trySemantic() is attempted outside them, see above. I think the correct solution for the problem is to remove the template instance from the member list of the enclosing scope again if instantiation failed while errors were gagged: https://github.com/D-Programming-Language/dmd/pull/364
Comment #2 by code — 2011-09-04T22:52:33Z
(I realize that A!short would never have a type, even if B!short could be instantiated, but this is not important here.)
Comment #3 by code — 2011-09-05T14:25:16Z
Comment #4 by code — 2011-09-05T14:31:14Z
*** Issue 6385 has been marked as a duplicate of this issue. ***
Comment #5 by bugzilla — 2011-09-05T16:50:52Z