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: improve error message for "too few values in struct literal" #51877

Closed
smasher164 opened this issue Mar 22, 2022 · 4 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@smasher164
Copy link
Member

smasher164 commented Mar 22, 2022

Does this issue reproduce with the latest release?

Yes (tested on 1.18)

What did you do?

https://go.dev/play/p/2-Us-h1omW-

package main

type A struct {
	F1 int
	F2 bool
}

func main() {
	_ = A{0}
}

What did you expect to see?

./prog.go:9:9: too few values in struct literal for A

What did you see instead?

./prog.go:9:9: too few values in struct literal

Although the error message has a line:column, I found it tedious to locate the struct that was not initialized properly when there was a lot of nested structs, i.e.

A{B{},C{D{}}}

It would be helpful for the error message to specify the type name of the struct that wasn't initialized properly.

@golang golang deleted a comment from malekmahmed Mar 23, 2022
@mknyszek
Copy link
Contributor

Which releases are you comparing output for?

CC @griesemer maybe?

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 23, 2022
@mknyszek mknyszek added this to the Go1.19 milestone Mar 23, 2022
@mknyszek
Copy link
Contributor

Putting this in the 1.19 milestone optimistically.

@smasher164
Copy link
Member Author

Which releases are you comparing output for?

Good point. I ran this on 1.18 (updated the description). On 1.17, I see the message

./prog.go:9:8: too few values in A{...}

which is much better.

@griesemer griesemer self-assigned this Mar 23, 2022
@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 23, 2022
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/394914 mentions this issue: go/types, types2: report struct type for literals with too few/many elements

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

4 participants