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: typed struct name not shown in error #48784

Closed
rsc opened this issue Oct 5, 2021 · 5 comments
Closed

cmd/compile: typed struct name not shown in error #48784

rsc opened this issue Oct 5, 2021 · 5 comments
Assignees
Milestone

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Oct 5, 2021

% cat /tmp/x.go
package p

type T struct {
	x int
	y int
	z int
}

var t T

var _ = t == nil
% go tool compile /tmp/x.go
/tmp/x.go:11:14: cannot convert untyped nil to struct{x int; y int; z int}
% go tool compile -G=0 /tmp/x.go
/tmp/x.go:11:11: invalid operation: t == nil (mismatched types T and nil)
% 

The old error, using the name and showing the == operation, was clearer.

In the real example I just hit, I had an os.Process instead of T, and the error was showing me the contents of os.Process instead of the name os.Process, which meant very little to me. I wasn't even sure whether it was the contents of os.Process and had to look it up.

/cc @griesemer @findleyr

@rsc rsc added this to the Go1.18 milestone Oct 5, 2021
@findleyr
Copy link
Contributor

@findleyr findleyr commented Oct 5, 2021

Thanks for the report, and the repro.

This is one of the areas where the go/types error messages differ from types2. go/types reports cannot use nil (untyped nil value) as T value in variable declaration.

I think this is just an oversight where we're taking the underlying and don't need to. I'll send a fix.

Loading

@findleyr findleyr self-assigned this Oct 5, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 5, 2021

Change https://golang.org/cl/353976 mentions this issue: cmd/compile/internal/types2: identify defined types in conversion errors

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 5, 2021

Change https://golang.org/cl/354049 mentions this issue: cmd/compile: better error message for invalid untyped nil conversion

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 5, 2021

Change https://golang.org/cl/354050 mentions this issue: go/types: better error message for invalid untyped nil conversion

Loading

@gopherbot gopherbot closed this in 375a1fb Oct 7, 2021
gopherbot pushed a commit that referenced this issue Oct 7, 2021
This is port of CL 354049 for types2 to go/type.

The change is identical, but for some tweaks to the error message/position
in tests, since when go/types reports the exact operation "cannot convert"
instead of the general "invalid operation" like types2.

Updates #48784

Change-Id: I3e99f2721501d23187fd0a8970eb1de28e0c41d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/354050
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 7, 2021

Change https://golang.org/cl/354631 mentions this issue: test/fixedbugs: fix issue48784.go to pass with -G=0

Loading

gopherbot pushed a commit that referenced this issue Oct 7, 2021
This test is currently failing in the longtest builders.

I do not know how or why the builders are adding the -G=0 parameter.

Updates #48784

Change-Id: I62248d3fbc47567a8c73b4868a2d4aeb0bc47bc3
Reviewed-on: https://go-review.googlesource.com/c/go/+/354631
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants