Unreviewed changes
1 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: src/cmd/compile/internal/types2/call.go
Insertions: 1, Deletions: 1.
@@ -846,7 +846,7 @@
// method expression
m, _ := obj.(*Func)
if m == nil {
- check.errorf(e.Sel, MissingFieldOrMethod, "%s.%s undefined (%s must be a value, not a type)", x.expr, sel, x.typ)
+ check.errorf(e.X, MissingFieldOrMethod, "operand for field selector %s must be value of type %s", sel, x.typ)
goto Error
}
```
```
The name of the file: src/go/types/call.go
Insertions: 1, Deletions: 1.
@@ -849,7 +849,7 @@
// method expression
m, _ := obj.(*Func)
if m == nil {
- check.errorf(e.Sel, MissingFieldOrMethod, "%s.%s undefined (%s must be a value, not a type)", x.expr, sel, x.typ)
+ check.errorf(e.X, MissingFieldOrMethod, "operand for field selector %s must be value of type %s", sel, x.typ)
goto Error
}
```
```
The name of the file: src/internal/types/testdata/check/expr3.go
Insertions: 3, Deletions: 3.
@@ -156,7 +156,7 @@
func method_expressions() {
_ = T.a /* ERROR "no field or method" */
- _ = T.x /* ERROR "T must be a value, not a type" */
+ _ = T /* ERROR "operand for field selector x must be value of type T" */ .x
_ = T.m /* ERROR "invalid method expression T.m (needs pointer receiver (*T).m)" */
_ = (*T).m
@@ -164,8 +164,8 @@
var g func(*T) = (*T).m
_, _ = f, g
- _ = T.y /* ERROR "T must be a value, not a type" */
- _ = (*T).y /* ERROR "*T must be a value, not a type" */
+ _ = T /* ERROR "operand for field selector y must be value of type T" */ .y
+ _ = ( /* ERROR "operand for field selector y must be value of type *T" */ *T).y
}
func struct_literals() {
```
```
The name of the file: src/internal/types/testdata/check/issues0.go
Insertions: 1, Deletions: 1.
@@ -351,7 +351,7 @@
}
func issue26234c() {
- T.x /* ERROR "T must be a value, not a type" */ ()
+ T /* ERROR "operand for field selector x must be value of type T" */ .x()
}
func issue35895() {
```
```
The name of the file: src/internal/types/testdata/fixedbugs/issue6814.go
Insertions: 3, Deletions: 3.
@@ -19,9 +19,9 @@
func _() {
_ = S.X // ERROR "S.X undefined (type S has no field or method X, but does have field x)"
- _ = S.E // ERROR "S.E undefined (S must be a value, not a type)"
- _ = S.x // ERROR "S.x undefined (S must be a value, not a type)"
- _ = S.e // ERROR "S.e undefined (S must be a value, not a type)"
+ _ = S /* ERROR "operand for field selector E must be value of type S" */ .E
+ _ = S /* ERROR "operand for field selector x must be value of type S" */ .x
+ _ = S /* ERROR "operand for field selector e must be value of type S" */ .e
_ = S.m
_ = S.n
```
Change information
Commit message:
go/types, types2: better error when selecting field on type rather than value
Fixes #6814.
Change-Id: I659670998f8e89400d03d40189e8c54f7e705cdc
Files:
- M src/cmd/compile/internal/types2/call.go
- M src/go/types/call.go
- M src/internal/types/testdata/check/expr3.go
- M src/internal/types/testdata/check/issues0.go
- A src/internal/types/testdata/fixedbugs/issue6814.go
Change size: S
Delta: 5 files changed, 43 insertions(+), 6 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Code-Review: +1 by Robert Griesemer, +2 by Alan Donovan
TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI