Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: compiler accepts invalid array type #13485

Closed
griesemer opened this issue Dec 4, 2015 · 3 comments
Closed

cmd/compile: compiler accepts invalid array type #13485

griesemer opened this issue Dec 4, 2015 · 3 comments
Milestone

Comments

@griesemer
Copy link
Contributor

var a [10]int                         // valid and accepted
var b [10.0]int                       // valid and accepted
var c [float64(10)]int                // invalid but accepted
var d [complex(10, 0)]int             // valid but not accepted
var e [complex128(complex(10, 0))]int // invalid and not accepted

(http://play.golang.org/p/YYb-ApQgjj)

The declaration of c is not valid because the length is of type float32. The spec says:
"The length is part of the array's type; it must evaluate to a non-negative constant representable by a value of type int."

(In other parts of the spec where we use similar wording, e.g. for array/slice indices, we do permit untyped constants representable as ints, but we reject non-integer-type values even if their values happen to be representable as integers.)

The declaration of d is valid because complex(10, 0) is an untyped constant that is representable as an int.

The declaration of e is correctly rejected and in contradiction to the acceptance of c; i.e., the compiler is not consistent.

For comparison:

  • go/types correctly rejects c and e and accepts the others
  • gccgo dies with an internal compiler error for type c [float64(10)]int and type e [complex128(complex(10, 0))]int, but accepts d.
@gopherbot
Copy link

CL https://golang.org/cl/18065 mentions this issue.

@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Dec 22, 2015
@gopherbot
Copy link

CL https://golang.org/cl/18100 mentions this issue.

@rsc rsc modified the milestones: Go1.8, Go1.7 May 17, 2016
@griesemer griesemer self-assigned this Jun 10, 2016
@gopherbot
Copy link

CL https://golang.org/cl/30456 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants