You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version go1.9.3 linux/amd64
Does this issue reproduce with the latest release?
1.9.3 is the latest version.
What operating system and processor architecture are you using (go env)?
amd64
linux
What did you do?
Try building this program:
1 package foo
2
3 import (
4 )
5
6 type Foo struct{
7 A int
8 B int
9 C interface{}
10 }
11
12 type Bar struct{
13 A string
14 }
15
16 func main() {
17 f := Foo{
18 1,
19 2,
20 3,
21 Bar{"hello"},
22 }
23 }
What did you expect to see?
An error message that leads me straight to the problem (i.e. that the Foo initialization has the wrong number of args).
What did you see instead?
./test.go:21:6: too many values in struct initializer
This is ambiguous, as it could apply to Foo or Bar. I had a real conundrum with a much larger struct whose definition was in another file, and two of us spent a long time trying to figure out what was wrong with Bar before realizing that it was embedded in a larger struct, and coincidentally on the last line. Could the error message be changed to say the following?
./test.go:21:6: too many values in initializer of struct Foo
Similarly, if you delete lines 19-20, you get:
./test.go:19:6: too few values in struct initializer
which has the same problem.
The text was updated successfully, but these errors were encountered:
mvdan
changed the title
Could build error specify which struct has the wrong number of args?
cmd/compile: make "struct initializer" errors more specific
Feb 7, 2018
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9.3 linux/amd64
Does this issue reproduce with the latest release?
1.9.3 is the latest version.
What operating system and processor architecture are you using (
go env
)?amd64
linux
What did you do?
Try building this program:
1 package foo
2
3 import (
4 )
5
6 type Foo struct{
7 A int
8 B int
9 C interface{}
10 }
11
12 type Bar struct{
13 A string
14 }
15
16 func main() {
17 f := Foo{
18 1,
19 2,
20 3,
21 Bar{"hello"},
22 }
23 }
What did you expect to see?
An error message that leads me straight to the problem (i.e. that the Foo initialization has the wrong number of args).
What did you see instead?
./test.go:21:6: too many values in struct initializer
This is ambiguous, as it could apply to Foo or Bar. I had a real conundrum with a much larger struct whose definition was in another file, and two of us spent a long time trying to figure out what was wrong with Bar before realizing that it was embedded in a larger struct, and coincidentally on the last line. Could the error message be changed to say the following?
./test.go:21:6: too many values in initializer of struct Foo
Similarly, if you delete lines 19-20, you get:
./test.go:19:6: too few values in struct initializer
which has the same problem.
The text was updated successfully, but these errors were encountered: