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: struct literal error prints struct definition instead of struct name #68184

Open
rsc opened this issue Jun 25, 2024 · 2 comments
Open
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jun 25, 2024

% cat /tmp/x.go
package main

type VeryLongStruct struct {
	A1  int
	A2  int
	A3  int
	A4  int
	A5  int
	A6  int
	A7  int
	A8  int
	A9  int
	A10 int
	A11 int
	A12 int
	A13 int
	A14 int
	A15 int
	A16 int
	A17 int
	A18 int
	A19 int
	A20 int
}

func main() {
	var x VeryLongStruct
	x.B2 = false

	xx := []VeryLongStruct{{B2: false}}
	_ = xx
}
% go build /tmp/x.go
# command-line-arguments
/tmp/x.go:28:4: x.B2 undefined (type VeryLongStruct has no field or method B2)
/tmp/x.go:30:26: unknown field B2 in struct literal of type struct{A1 int; A2 int; A3 int; A4 int; A5 int; A6 int; A7 int; A8 int; A9 int; A10 int; A11 int; A12 int; A13 int; A14 int; A15 int; A16 int; A17 int; A18 int; A19 int; A20 int}
% 

Note that the plain x.B2 assignment prints a nice error mentioning VeryLongStruct by name.

In contrast, the same assignment in the struct literal prints the actual struct definition, which is too long to be useful. Saying

/tmp/x.go:30:26: unknown field B2 in struct literal of type VeryLongStruct

would be better.

/cc @griesemer

@rsc rsc added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 25, 2024
@rsc rsc added this to the Go1.24 milestone Jun 25, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jun 25, 2024
@griesemer griesemer self-assigned this Jun 25, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/595075 mentions this issue: go/types, types2: report type name in comp. literal error, if possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

4 participants