Bug 8848 – Array literals and AA literals are rejected as template value parameters

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-18T02:41:00Z
Last change time
2015-06-09T05:11:58Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2012-10-18T02:41:18Z
The template spec says that they are valid (both D1 and D2), but template Bleherg(int[int] X) {} gives: bug.d(1): Error: arithmetic/string type expected for value-parameter, not int[int] --- However, the compiler accepts them as template value parameters when used with in a tuple argument. The example below works correctly with both D1 and D2. ----- class C ( T ... ) { pragma(msg, "The keys are ", T[0].keys); pragma(msg, "The values are ", T[0].values); } alias C!( [ "abc"[] : 73, "sdg":6 ] ) G1; alias C!( [ 22354.56 : 273, 43565.12:96 ] ) G2; ----- Additionally, the name mangling for both array literals and AA literals is clearly documented in the spec ABI page. The error message is erroneous.
Comment #1 by bearophile_hugs — 2012-10-18T02:56:16Z
(In reply to comment #0) > The template spec says that they are valid (both D1 and D2), So are associative arrays accepted, but simple arrays aren't? template Foo(int[] X) {} template Bar(int[5] X) {} void main() {} ==> test.d(1): Error: arithmetic/string type expected for value-parameter, not int[] test.d(2): Error: arithmetic/string type expected for value-parameter, not int[5u]
Comment #2 by clugdbug — 2012-10-19T02:40:26Z
(In reply to comment #1) > (In reply to comment #0) > > The template spec says that they are valid (both D1 and D2), > > So are associative arrays accepted, but simple arrays aren't? > > template Foo(int[] X) {} > template Bar(int[5] X) {} > void main() {} No, the current DMD accepts neither arrays or AAs in declarations. But both can be passed in template tuple parameters.
Comment #3 by andrej.mitrovich — 2013-08-22T14:41:26Z
(In reply to comment #2) > (In reply to comment #1) > > (In reply to comment #0) > > > The template spec says that they are valid (both D1 and D2), > > > > So are associative arrays accepted, but simple arrays aren't? > > > > template Foo(int[] X) {} > > template Bar(int[5] X) {} > > void main() {} > > No, the current DMD accepts neither arrays or AAs in declarations. But both can > be passed in template tuple parameters. W.r.t. arrays, is this just a parser issue? It's odd that we have this situation: ----- // template Foo(ubyte[]) { } // nogo template Bar(T...) { } // ok void main() { enum ubyte[] x = [1, 2]; // alias y = Foo!(x); alias z = Bar!(x); // ok } -----
Comment #4 by yebblies — 2013-11-23T22:57:22Z
Comment #5 by github-bugzilla — 2014-02-08T10:48:06Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/8d8c7538922e0e863bdc0160e88d797c58d8337f Fix Issue 8848 - Array literals and AA literals are rejected as template value parameters
Comment #6 by k.hara.pg — 2014-10-02T12:11:39Z
*** Issue 3881 has been marked as a duplicate of this issue. ***