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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6602 - Invalid template instantiations »leaked« by is(typeof())/__traits(compiles, ...)/Type::trySemantic
Summary: Invalid template instantiations »leaked« by is(typeof())/__traits(compiles, ......
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Mac OS X
: P2 critical
Assignee: No Owner
URL:
Keywords: patch
: 6385 (view as issue list)
Depends on:
Blocks:
Reported: 2011年09月04日 21:29 UTC by David Nadlinger
Modified: 2011年09月05日 16:50 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description David Nadlinger 2011年09月04日 21:29:25 UTC
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 David Nadlinger 2011年09月04日 22:25:58 UTC
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 David Nadlinger 2011年09月04日 22:52:33 UTC
(I realize that A!short would never have a type, even if B!short could be instantiated, but this is not important here.)
Comment 4 David Nadlinger 2011年09月05日 14:31:14 UTC
*** Issue 6385 has been marked as a duplicate of this issue. ***


AltStyle によって変換されたページ (->オリジナル) /