Thread overview
[Issue 6602] New: Invalid template instantiations »leaked« by is(typeof())/__traits(compiles, …)/Type::trySemantic
Sep 05, 2011
klickverbot
Sep 05, 2011
klickverbot
Sep 05, 2011
klickverbot
Sep 05, 2011
klickverbot
Sep 05, 2011
klickverbot
Sep 05, 2011
Walter Bright
September 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6602

           Summary: Invalid template instantiations »leaked« by
                    is(typeof())/__traits(compiles, …)/Type::trySemantic
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: code@klickverbot.at


--- Comment #0 from klickverbot <code@klickverbot.at> 2011-09-04 21:29:25 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6602



--- Comment #1 from klickverbot <code@klickverbot.at> 2011-09-04 22:25:58 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6602


klickverbot <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #2 from klickverbot <code@klickverbot.at> 2011-09-04 22:52:33 PDT ---
(I realize that A!short would never have a type, even if B!short could be instantiated, but this is not important here.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6602


klickverbot <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #3 from klickverbot <code@klickverbot.at> 2011-09-05 14:25:16 PDT ---
https://github.com/D-Programming-Language/dmd/commit/3da0a36698b9cc424dbc8f6e7b2786768ae50f84

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6602


klickverbot <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com


--- Comment #4 from klickverbot <code@klickverbot.at> 2011-09-05 14:31:14 PDT ---
*** Issue 6385 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6602


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2011-09-05 16:50:52 PDT ---
https://github.com/D-Programming-Language/dmd/commit/3da0a36698b9cc424dbc8f6e7b2786768ae50f84

https://github.com/D-Programming-Language/dmd/commit/5c236d7583f05d10aa55126e16abd00b6e4ff458

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------