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: make "struct initializer" errors more specific #23732

Closed
kschon opened this issue Feb 7, 2018 · 2 comments
Closed

cmd/compile: make "struct initializer" errors more specific #23732

kschon opened this issue Feb 7, 2018 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@kschon
Copy link

kschon commented 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.

@mvdan 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
@mvdan
Copy link
Member

mvdan commented Feb 7, 2018

/cc @mdempsky @griesemer

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Feb 7, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Feb 7, 2018
@odeke-em odeke-em self-assigned this Feb 11, 2018
@gopherbot
Copy link

Change https://golang.org/cl/93277 mentions this issue: cmd/compile: report the struct type in invalid number of initializer values

@golang golang locked and limited conversation to collaborators Feb 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants