Skip to content

spec: array constants #6388

Closed
Closed
@gopherbot

Description

@gopherbot

by RickySeltzer:

The syntax for initializing arrays of byte arrays is excessively restrictive and very
inelegant and inconvenient.  Both of these ought to compile and do the obvious thing.

See Also issue #6386: http://code.google.com/p/go/issues/detail\?id\=6386

There are TWO problems.
 I) Arrays of constants can not be declared const.
 II) The syntax requires peppering the source with REDUNDANT redeclarations of '[]byte' before each word.

    const epigram [][]byte = [][]byte {
    []byte("He"), []byte("who"), []byte("laughs"),
    []byte("last"), []byte("laughs"), []byte("best."),
    }

    var epigram2 [][]byte = [][]byte {
    "He", "who", "laughs",
    "last", "laughs", "best.",
    }

1. What is a short input program that triggers the error?
http://play.golang.org/p/g7A-bNLV7L

2. What is the full compiler output?
prog.go:13: cannot use "He" (type string) as type []byte in array element
prog.go:13: cannot use "who" (type string) as type []byte in array element
prog.go:13: cannot use "laughs" (type string) as type []byte in array element
prog.go:14: cannot use "last" (type string) as type []byte in array element
prog.go:14: cannot use "laughs" (type string) as type []byte in array element
prog.go:14: cannot use "best." (type string) as type []byte in array element
prog.go:15: const initializer <T> literal is not a constant

3. What version of the compiler are you using?  (Run it with the -V flag.)
any

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions