Skip to content

cmd/compile: improve error message for "too few values in struct literal" #51877

@smasher164

Description

@smasher164

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions