[Issue 9443] New: Struct literal syntax in associative array literals too

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 2 13:43:31 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9443

           Summary: Struct literal syntax in associative array literals
                    too
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-02-02 13:43:27 PST ---
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])
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list