D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4333 - Cannot use tuple of local symbols in constraint nor static if
Summary: Cannot use tuple of local symbols in constraint nor static if
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks: 4312
  Show dependency treegraph
 
Reported: 2010-06-16 13:47 UTC by Shin Fujishiro
Modified: 2014-02-15 02:45 UTC (History)
5 users (show)

See Also:


Attachments
A struct, using which causes some problems. (6.42 KB, application/octet-stream)
2011-07-28 07:09 UTC, Gor Gyolchanyan
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Shin Fujishiro 2010-06-16 13:47:16 UTC
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
}
--------------------
Comment 1 Andrej Mitrovic 2011-05-26 14:13:45 UTC
I can't reproduce this on 2.053. Can you confirm?
Comment 2 yebblies 2011-07-10 00:59:19 UTC
These all seem to work on dmd2.054
Comment 3 Gor Gyolchanyan 2011-07-28 06:40:47 UTC
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.
Comment 4 yebblies 2011-07-28 06:51:23 UTC
(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.
Comment 5 Gor Gyolchanyan 2011-07-28 07:09:35 UTC
Created attachment 1014 [details]
A struct, using which causes some problems.
Comment 6 Gor Gyolchanyan 2011-07-28 07:10:37 UTC
(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.
Comment 7 David Nadlinger 2011-09-15 11:46:53 UTC
(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.