aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2024-01-31 15:02:31 -0800
committerRobert Griesemer <gri@google.com>2024-02-07 16:41:56 +0000
commitf81e4986733bc18ec2bef16549534b9029756444 (patch)
treedc28bd7c6f5a47b8b5763a2fdf50f7b6692e2db2 /test
parent39ec246e739a787375b00acd92c10311863575a2 (diff)
downloadgo-f81e4986733bc18ec2bef16549534b9029756444.tar.gz
go-f81e4986733bc18ec2bef16549534b9029756444.zip
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>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue22794.go2
-rw-r--r--test/fixedbugs/issue25727.go4
2 files changed, 3 insertions, 3 deletions
diff --git a/test/fixedbugs/issue22794.go b/test/fixedbugs/issue22794.go
index 933c83dc5b..fb5873e8e5 100644
--- a/test/fixedbugs/issue22794.go
+++ b/test/fixedbugs/issue22794.go
@@ -15,7 +15,7 @@ func main() {
i1 := it{Floats: true}
if i1.floats { // ERROR "(type it .* field or method floats, but does have field Floats)|undefined field or method"
}
- i2 := &it{floats: false} // ERROR "(but does have field Floats)|unknown field|declared and not used"
+ i2 := &it{floats: false} // ERROR "cannot refer to unexported field floats in struct literal|unknown field|declared and not used"
_ = &it{InneR: "foo"} // ERROR "(but does have field inner)|unknown field"
_ = i2
}
diff --git a/test/fixedbugs/issue25727.go b/test/fixedbugs/issue25727.go
index 06b2e2cac7..27c60a1764 100644
--- a/test/fixedbugs/issue25727.go
+++ b/test/fixedbugs/issue25727.go
@@ -11,11 +11,11 @@ import "net/http"
var s = http.Server{}
var _ = s.doneChan // ERROR "s.doneChan undefined .cannot refer to unexported field or method doneChan.$|unexported field or method|s.doneChan undefined"
var _ = s.DoneChan // ERROR "s.DoneChan undefined .type http.Server has no field or method DoneChan.$|undefined field or method"
-var _ = http.Server{tlsConfig: nil} // ERROR "unknown field tlsConfig in struct literal.+ .but does have TLSConfig.$|unknown field .?tlsConfig.? in .?http.Server|unknown field"
+var _ = http.Server{tlsConfig: nil} // ERROR "cannot refer to unexported field tlsConfig in struct literal|unknown field .?tlsConfig.? in .?http.Server|unknown field"
var _ = http.Server{DoneChan: nil} // ERROR "unknown field DoneChan in struct literal of type http.Server$|unknown field .?DoneChan.? in .?http.Server"
type foo struct {
bar int
}
-var _ = &foo{bAr: 10} // ERROR "unknown field bAr in struct literal.+ .but does have bar.$|unknown field .?bAr.? in .?foo|unknown field"
+var _ = &foo{bAr: 10} // ERROR "cannot refer to unexported field bAr in struct literal|unknown field .?bAr.? in .?foo|unknown field"