burner / bugzilla_migration_test

0 stars 0 forks source link

Allow AA literals to initialize static variables #19

Open burner opened 16 years ago

burner commented 16 years ago

davidl reported this on 2007-10-13T07:58:08Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=1578

CC List

Description

const MTBit8 = 1; const MTBit16 = 2; const MTBit32 = 3; const MTBit64 = 4; const MTBit80 = 4; const MTBit128 = 5; static int sizemap[int]=[0:0,MTBit8:byte.sizeof, MTBit16:int.sizeof, MTBit32:8, MTBit64:long.sizeof, MTBit80:16];

burner commented 16 years ago

matti.niemenmaa+dbugzilla commented on 2007-10-13T08:21:12Z

This is documented, and hence an enhancement request: "An AssocArrayLiteral cannot be used to statically initialize anything."

http://www.digitalmars.com/d/1.0/expression.html#AssocArrayLiteral

burner commented 11 years ago

clugdbug commented on 2012-09-27T01:14:26Z

Reduced test case:

static int sizemap[int]= [0:0, 1:1, 2:4, 3:8, 4:8, 4:16];

changed title from "const initializer rejected".

burner commented 9 years ago

yebblies commented on 2015-04-11T03:39:03Z

Issue 6238 has been marked as a duplicate of this issue.

burner commented 6 years ago

gooberman commented on 2018-05-20T19:35:59Z

Came here from issue 6238

10.5 years and this is still a problem. Encountered when trying to assign AA literal to a struct member.

See https://run.dlang.io/is/BDVjxP for another example.

burner commented 6 years ago

dmitry.olsh (@DmitryOlshansky) commented on 2018-05-22T09:08:59Z

Issue 5279 has been marked as a duplicate of this issue.

burner commented 3 years ago

mingwu commented on 2021-04-12T21:42:02Z

(In reply to Don from comment #2)

Reduced test case:

static int sizemap[int]= [0:0, 1:1, 2:4, 3:8, 4:8, 4:16];

changed title from "const initializer rejected".

The work-around is:

enum int[int] sizemap= [0:0, 1:1, 2:4, 3:8, 4:8, 4:16];

BTW, this is a very old issue, if it's not intended to be fixed, can we add to the doc, and close it?

burner commented 3 years ago

gooberman commented on 2021-04-12T22:09:58Z

(In reply to mw from comment #6)

The work-around is:

enum int[int] sizemap= [0:0, 1:1, 2:4, 3:8, 4:8, 4:16];

That's not a workaround at all. That's defining a constant. My example from 2018 even illustrates exactly this, and that assigning the constant to a static variable does not work.