]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: better errors for non-existing fields or methods
authorRobert Griesemer <gri@golang.org>
Wed, 31 Jan 2024 23:02:31 +0000 (15:02 -0800)
committerRobert Griesemer <gri@google.com>
Wed, 7 Feb 2024 16:41:56 +0000 (16:41 +0000)
commitf81e4986733bc18ec2bef16549534b9029756444
treedc28bd7c6f5a47b8b5763a2fdf50f7b6692e2db2
parent39ec246e739a787375b00acd92c10311863575a2
go/types, types2: better errors for non-existing fields or methods

This CL improves the error messages reported when a field or method
name is used that doesn't exist. It brings the error messges on par
(or better) with the respective errors reported before Go 1.18 (i.e.
before switching to the new type checker):

Make case distinctions based on whether a field/method is exported
and how it is spelled. Factor out that logic into a new function
(lookupError) in a new file (errsupport.go), which is generated for
go/types. Use lookupError when reporting selector lookup errors
and missing struct field keys.

Add a comprehensive set of tests (lookup2.go) and spot tests for
the two cases brought up by the issue at hand.

Adjusted existing tests as needed.

Fixes #49736.

Change-Id: I2f439948dcd12f9bd1a258367862d8ff96e32305
Reviewed-on: https://go-review.googlesource.com/c/go/+/560055
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
12 files changed:
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/errsupport.go [new file with mode: 0644]
src/cmd/compile/internal/types2/expr.go
src/go/types/call.go
src/go/types/errsupport.go [new file with mode: 0644]
src/go/types/expr.go
src/go/types/generate_test.go
src/internal/types/testdata/check/lookup1.go [moved from src/internal/types/testdata/check/lookup.go with 94% similarity]
src/internal/types/testdata/check/lookup2.go [new file with mode: 0644]
src/internal/types/testdata/fixedbugs/issue49736.go [new file with mode: 0644]
test/fixedbugs/issue22794.go
test/fixedbugs/issue25727.go