[Issue 4333] New: Cannot use tuple of local symbols in constraint nor static if

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 16 13:47:17 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4333

           Summary: Cannot use tuple of local symbols in constraint nor
                    static if
           Product: D
           Version: 2.041
          Platform: Other
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: rsinfu at gmail.com


--- Comment #0 from Shin Fujishiro <rsinfu at gmail.com> 2010-06-16 13:47:16 PDT ---
When a template is instantiated with a tuple of local symbols, using those
local symbols in template-constraint and/or static-if causes a compile error. 
See (1) and (2) below.

The error does not occur if the tuple is evaluated outside static-if scope
before used in a static if.  See (3).


(1) Using a tuple containing a local delegate literal in a template contraint
causes an error:
--------------------
template Test(a...)
    if (a.length == 1) // <-- !!
{
}
void main()
{
    alias Test!((int a) { return a; }) test;
        // Error: delegate test.__dgliteral1 cannot access frame of
        //        function __dgliteral1
}
--------------------

(2) Using the same tuple in a static if does not compile for the same error:
--------------------
template Test(a...)
{
    static if (typeof(a[0]).stringof) {} // <-- !!
}
void main()
{
    alias Test!((int a) { return a; }) test;
        // Error: delegate test.__dgliteral1 cannot access frame of
        //        function __dgliteral1
}
--------------------

(3) NOTE: The error does not occur if the tuple is evaluated outside static-if
scope before used in a static if:
--------------------
template Test(a...)
{
    alias typeof(a) at; // evaluated once (error w/o this line)
    static if (a.length == 1) {}
}
void main()
{
    alias Test!((int a) { return a; }) test; // ok
}
--------------------

(4) The error does not occur if the argument is not a tuple:
--------------------
template Test(alias a) // not tuple
{
    static if (typeof(a).stringof) {}
}
void main()
{
    alias Test!((int a) { return a; }) test; // ok
}
--------------------

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


More information about the Digitalmars-d-bugs mailing list