-
Notifications
You must be signed in to change notification settings - Fork 18k
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: can't specify value for blank fields of array types. #38690
Comments
Change https://golang.org/cl/230121 mentions this issue: |
The error message looks wrong but it's not obvious to me that the program should work. Is a composite literal allowed to set the value of a |
We allow initializing blank, non-array-typed fields in non-keyed composite literals, so we should probably allow blank, array-typed fields too. |
OK, SGTM. |
It looks struct literals also have this problem, but slice literals not. package main
type T = struct{y int} // struct literals also fail to compile
//type T = [1]int
//type T = []int // slice literals are ok
type S struct{x int; _ T}
var x, y = S{1, T{2}}, S{1, T{2}} // ok
func main() {
println(S{1, T{2}}.x == S{1, T{3}}.x) // cannot use _ as value
} |
Does it also only happen in structs with <= 4 fields? If so, the bug might be in the inlined struct comparison code in walkCompare in walk.go. |
Seems that involves alias type, using struct directly compiling ok. |
Ah no, so it works with 0-field struct.
It's also ok with |
Fixes golang#38690 Change-Id: I3544daf617fddc0f89636265c113001178d16b0c Reviewed-on: https://go-review.googlesource.com/c/go/+/230121 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
What did you expect to see?
Compiles ok.
What did you see instead?
Failed to compile.
BTW, it compiles ok with gccgo.
The text was updated successfully, but these errors were encountered: