Bug 9443 – Struct literal syntax in associative array literals too

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-02T13:43:27Z
Last change time
2024-12-13T18:03:54Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: dmd#18516 →

Comments

Comment #0 by bearophile_hugs — 2013-02-02T13:43:27Z
Array literals support the {} syntax to create structs, while associative array literals don't: struct Foo { int x; } void main() { auto a1 = [Foo(10), Foo(20)]; // OK Foo[] a2 = [{10}, {20}]; // OK auto aa1 = [Foo(1): Foo(10), Foo(2): Foo(20)]; // OK Foo[Foo] aa2 = [{1}: {10}, {2}: {20}]; // Line6, error } DMD 2.062alpha gives: temp.d(6): Error: not an associative array initializer That syntax is partially supported by Go language maps: package main import "fmt" type Foo struct { x int } func main() { aa := map[int]Foo {1: {10}, 2: {20}} fmt.Println(aa[2]) }
Comment #1 by razvan.nitu1305 — 2023-01-31T11:10:54Z
*** Issue 18611 has been marked as a duplicate of this issue. ***
Comment #2 by robert.schadek — 2024-12-13T18:03:54Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18516 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB