www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4333] New: Cannot use tuple of local symbols in constraint nor static if

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: rsinfu gmail.com


--- Comment #0 from Shin Fujishiro <rsinfu 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: -------
Jun 16 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4333


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2011-05-26
14:13:45 PDT ---
I can't reproduce this on 2.053. Can you confirm?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4333


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |WORKSFORME


--- Comment #2 from yebblies <yebblies gmail.com> 2011-07-10 17:59:19 EST ---
These all seem to work on dmd2.054

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 10 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4333


Gor Gyolchanyan <gor boloneum.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |gor boloneum.com
         Resolution|WORKSFORME                  |


--- Comment #3 from Gor Gyolchanyan <gor boloneum.com> 2011-07-28 06:40:47 PDT
---
No, it still doesn't work. I tried making a template and passing it a tuple of
mixed literals and local variable names and the same error occurred.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4333



--- Comment #4 from yebblies <yebblies gmail.com> 2011-07-28 23:51:23 EST ---
(In reply to comment #3)
 No, it still doesn't work. I tried making a template and passing it a tuple of
 mixed literals and local variable names and the same error occurred.
Please post a test case if you have one. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 28 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4333



--- Comment #5 from Gor Gyolchanyan <gor boloneum.com> 2011-07-28 07:09:35 PDT
---
Created an attachment (id=1014)
A struct, using which causes some problems.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4333



--- Comment #6 from Gor Gyolchanyan <gor boloneum.com> 2011-07-28 07:10:37 PDT
---
(In reply to comment #4)
 (In reply to comment #3)
 No, it still doesn't work. I tried making a template and passing it a tuple of
 mixed literals and local variable names and the same error occurred.
Please post a test case if you have one.
Can't reproduce that problem ATM, but another problem was discovered: Hsec[] test(items...)() { return Hsec(items); } unittest { int i; float f; char c; foreach(z; test!(5, i, 2.3f, f, 'a', c)) { writeln(z.type, " ", z.kind); } } this code causes DMD to crash. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 28 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4333


klickverbot <code klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |code klickverbot.at
         Resolution|                            |WORKSFORME


--- Comment #7 from klickverbot <code klickverbot.at> 2011-09-15 11:46:53 PDT
---
(In reply to comment #6)
 Can't reproduce that problem ATM, but another problem was discovered:
Just pasting the code from the attachment and your test case works fine here (latest DMD on OS X x86) – please provide more detailed instructions for reproducing the problem. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 15 2011