Skip to content

cmd/compile: struct literal error prints struct definition instead of struct name #68184

@rsc

Description

@rsc
% 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

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions