Bug 4333 – Cannot use tuple of local symbols in constraint nor static if

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-06-16T13:47:00Z
Last change time
2014-02-15T02:45:39Z
Keywords
rejects-valid
Assigned to
nobody
Creator
rsinfu
Blocks
4312

Attachments

IDFilenameSummaryContent-TypeSize
1014hsec.dA struct, using which causes some problems.application/octet-stream6575

Comments

Comment #0 by rsinfu — 2010-06-16T13:47:16Z
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 by andrej.mitrovich — 2011-05-26T14:13:45Z
I can't reproduce this on 2.053. Can you confirm?
Comment #2 by yebblies — 2011-07-10T00:59:19Z
These all seem to work on dmd2.054
Comment #3 by gor — 2011-07-28T06:40:47Z
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 by yebblies — 2011-07-28T06:51:23Z
(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 by gor — 2011-07-28T07:09:35Z
Created attachment 1014 A struct, using which causes some problems.
Comment #6 by gor — 2011-07-28T07:10:37Z
(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 by code — 2011-09-15T11:46:53Z
(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.