1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:10:12 -07:00

go/types: fix column reporting of invalid selector names

Fixes #24645

Change-Id: I914674451b6667c3ebaf012893503d9de58991ee
Reviewed-on: https://go-review.googlesource.com/104155
Run-TryBot: Giovanni Bajo <rasky@develer.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Giovanni Bajo 2018-04-02 23:13:43 +02:00 committed by Robert Griesemer
parent f1deee0e8c
commit 690324408f
9 changed files with 50 additions and 50 deletions

View File

@ -323,12 +323,12 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) {
exp := pkg.scope.Lookup(sel) exp := pkg.scope.Lookup(sel)
if exp == nil { if exp == nil {
if !pkg.fake { if !pkg.fake {
check.errorf(e.Pos(), "%s not declared by package %s", sel, pkg.name) check.errorf(e.Sel.Pos(), "%s not declared by package %s", sel, pkg.name)
} }
goto Error goto Error
} }
if !exp.Exported() { if !exp.Exported() {
check.errorf(e.Pos(), "%s not exported by package %s", sel, pkg.name) check.errorf(e.Sel.Pos(), "%s not exported by package %s", sel, pkg.name)
// ok to continue // ok to continue
} }
check.recordUse(e.Sel, exp) check.recordUse(e.Sel, exp)
@ -373,11 +373,11 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) {
switch { switch {
case index != nil: case index != nil:
// TODO(gri) should provide actual type where the conflict happens // TODO(gri) should provide actual type where the conflict happens
check.invalidOp(e.Pos(), "ambiguous selector %s", sel) check.invalidOp(e.Sel.Pos(), "ambiguous selector %s", sel)
case indirect: case indirect:
check.invalidOp(e.Pos(), "%s is not in method set of %s", sel, x.typ) check.invalidOp(e.Sel.Pos(), "%s is not in method set of %s", sel, x.typ)
default: default:
check.invalidOp(e.Pos(), "%s has no field or method %s", x, sel) check.invalidOp(e.Sel.Pos(), "%s has no field or method %s", x, sel)
} }
goto Error goto Error
} }
@ -386,7 +386,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) {
// method expression // method expression
m, _ := obj.(*Func) m, _ := obj.(*Func)
if m == nil { if m == nil {
check.invalidOp(e.Pos(), "%s has no method %s", x, sel) check.invalidOp(e.Sel.Pos(), "%s has no method %s", x, sel)
goto Error goto Error
} }

View File

@ -61,7 +61,7 @@ type (
type ( type (
p1 pi /* ERROR "no field or method foo" */ .foo p1 pi.foo /* ERROR "no field or method foo" */
p2 unsafe.Pointer p2 unsafe.Pointer
) )
@ -189,10 +189,10 @@ func f2(x *f2 /* ERROR "not a type" */ ) {}
func f3() (x f3 /* ERROR "not a type" */ ) { return } func f3() (x f3 /* ERROR "not a type" */ ) { return }
func f4() (x *f4 /* ERROR "not a type" */ ) { return } func f4() (x *f4 /* ERROR "not a type" */ ) { return }
func (S0) m1(x S0 /* ERROR "field or method" */ .m1) {} func (S0) m1(x S0.m1 /* ERROR "field or method" */ ) {}
func (S0) m2(x *S0 /* ERROR "field or method" */ .m2) {} func (S0) m2(x *S0.m2 /* ERROR "field or method" */ ) {}
func (S0) m3() (x S0 /* ERROR "field or method" */ .m3) { return } func (S0) m3() (x S0.m3 /* ERROR "field or method" */ ) { return }
func (S0) m4() (x *S0 /* ERROR "field or method" */ .m4) { return } func (S0) m4() (x *S0.m4 /* ERROR "field or method" */ ) { return }
// interfaces may not have any blank methods // interfaces may not have any blank methods
type BlankI interface { type BlankI interface {

View File

@ -64,7 +64,7 @@ var (
t13 int = a /* ERROR "shifted operand" */ << d t13 int = a /* ERROR "shifted operand" */ << d
t14 int = i << j /* ERROR "must be unsigned" */ t14 int = i << j /* ERROR "must be unsigned" */
t15 math /* ERROR "not in selector" */ t15 math /* ERROR "not in selector" */
t16 math /* ERROR "not declared" */ .xxx t16 math.xxx /* ERROR "not declared" */
t17 math /* ERROR "not a type" */ .Pi t17 math /* ERROR "not a type" */ .Pi
t18 float64 = math.Pi * 10.0 t18 float64 = math.Pi * 10.0
t19 int = t1 /* ERROR "cannot call" */ () t19 int = t1 /* ERROR "cannot call" */ ()

View File

@ -19,7 +19,7 @@ func _() {
) )
var t T3 var t T3
_ = t /* ERROR "ambiguous selector" */ .X _ = t.X /* ERROR "ambiguous selector" */
} }
func _() { func _() {
@ -31,7 +31,7 @@ func _() {
) )
var t T4 var t T4
_ = t /* ERROR "ambiguous selector" */ .X _ = t.X /* ERROR "ambiguous selector" */
} }
func issue4355() { func issue4355() {
@ -44,7 +44,7 @@ func issue4355() {
) )
var t T5 var t T5
_ = t /* ERROR "ambiguous selector" */ .X _ = t.X /* ERROR "ambiguous selector" */
} }
func _() { func _() {
@ -54,7 +54,7 @@ func _() {
type T struct{ A; B } type T struct{ A; B }
var t T var t T
_ = t /* ERROR "ambiguous selector" */ .State _ = t.State /* ERROR "ambiguous selector" */
} }
// Embedded fields can be predeclared types. // Embedded fields can be predeclared types.
@ -118,8 +118,8 @@ func _() {
var p P var p P
_ = p.x _ = p.x
_ = p /* ERROR "no field or method" */ .m _ = p.m /* ERROR "no field or method" */
_ = P /* ERROR "no field or method" */ .m _ = P.m /* ERROR "no field or method" */
} }
// Borrowed from the FieldByName test cases in reflect/all_test.go. // Borrowed from the FieldByName test cases in reflect/all_test.go.
@ -209,9 +209,9 @@ type S13 struct {
} }
func _() { func _() {
_ = struct /* ERROR "no field or method" */ {}{}.Foo _ = struct{}{}.Foo /* ERROR "no field or method" */
_ = S0{}.A _ = S0{}.A
_ = S0 /* ERROR "no field or method" */ {}.D _ = S0{}.D /* ERROR "no field or method" */
_ = S1{}.A _ = S1{}.A
_ = S1{}.B _ = S1{}.B
_ = S1{}.S0 _ = S1{}.S0
@ -220,17 +220,17 @@ func _() {
_ = S2{}.S1 _ = S2{}.S1
_ = S2{}.B _ = S2{}.B
_ = S2{}.C _ = S2{}.C
_ = S2 /* ERROR "no field or method" */ {}.D _ = S2{}.D /* ERROR "no field or method" */
_ = S3 /* ERROR "ambiguous selector" */ {}.S1 _ = S3{}.S1 /* ERROR "ambiguous selector" */
_ = S3{}.A _ = S3{}.A
_ = S3 /* ERROR "ambiguous selector" */ {}.B _ = S3{}.B /* ERROR "ambiguous selector" */
_ = S3{}.D _ = S3{}.D
_ = S3{}.E _ = S3{}.E
_ = S4{}.A _ = S4{}.A
_ = S4 /* ERROR "no field or method" */ {}.B _ = S4{}.B /* ERROR "no field or method" */
_ = S5 /* ERROR "ambiguous selector" */ {}.X _ = S5{}.X /* ERROR "ambiguous selector" */
_ = S5{}.Y _ = S5{}.Y
_ = S10 /* ERROR "ambiguous selector" */ {}.X _ = S10{}.X /* ERROR "ambiguous selector" */
_ = S10{}.Y _ = S10{}.Y
} }
@ -306,4 +306,4 @@ type R22 R21
type R23 R21 type R23 R21
type R24 R21 type R24 R21
var _ = R0 /* ERROR "ambiguous selector" */ {}.X var _ = R0{}.X /* ERROR "ambiguous selector" */

View File

@ -190,8 +190,8 @@ type eD struct {
} }
var ( var (
_ = eD /* ERROR ambiguous selector */ {}.xf _ = eD{}.xf /* ERROR ambiguous selector */
_ = eD /* ERROR ambiguous selector */ {}.xm _ = eD{}.xm /* ERROR ambiguous selector */
) )
var ( var (

View File

@ -153,17 +153,17 @@ type T struct {
func (*T) m() {} func (*T) m() {}
func method_expressions() { func method_expressions() {
_ = T /* ERROR "no field or method" */ .a _ = T.a /* ERROR "no field or method" */
_ = T /* ERROR "has no method" */ .x _ = T.x /* ERROR "has no method" */
_ = T /* ERROR "not in method set" */ .m _ = T.m /* ERROR "not in method set" */
_ = (*T).m _ = (*T).m
var f func(*T) = T /* ERROR "not in method set" */ .m var f func(*T) = T.m /* ERROR "not in method set" */
var g func(*T) = (*T).m var g func(*T) = (*T).m
_, _ = f, g _, _ = f, g
_ = T /* ERROR "has no method" */ .y _ = T.y /* ERROR "has no method" */
_ = ( /* ERROR "has no method" */ *T).y _ = (*T).y /* ERROR "has no method" */
} }
func struct_literals() { func struct_literals() {

View File

@ -32,7 +32,7 @@ import f2 "fmt"
// reflect.flag must not be visible in this package // reflect.flag must not be visible in this package
type flag int type flag int
type _ reflect /* ERROR "not exported" */ .flag type _ reflect.flag /* ERROR "not exported" */
// imported package name may conflict with local objects // imported package name may conflict with local objects
type reflect /* ERROR "reflect already declared" */ int type reflect /* ERROR "reflect already declared" */ int

View File

@ -84,7 +84,7 @@ func issue10979() {
nosuchtype /* ERROR undeclared name: nosuchtype */ nosuchtype /* ERROR undeclared name: nosuchtype */
} }
type _ interface { type _ interface {
fmt /* ERROR Nosuchtype not declared by package fmt */ .Nosuchtype fmt.Nosuchtype /* ERROR Nosuchtype not declared by package fmt */
} }
type _ interface { type _ interface {
nosuchpkg /* ERROR undeclared name: nosuchpkg */ .Nosuchtype nosuchpkg /* ERROR undeclared name: nosuchpkg */ .Nosuchtype

View File

@ -29,7 +29,7 @@ type T3 struct {
func _() { func _() {
var ( var (
_ func(T0) = T0.v0 _ func(T0) = T0.v0
_ = T0 /* ERROR "not in method set" */ .p0 _ = T0.p0 /* ERROR "not in method set" */
_ func (*T0) = (*T0).v0 _ func (*T0) = (*T0).v0
_ func (*T0) = (*T0).p0 _ func (*T0) = (*T0).p0
@ -40,7 +40,7 @@ func _() {
_ func(T2) = T2.p2 _ func(T2) = T2.p2
_ func(T3) = T3.v0 _ func(T3) = T3.v0
_ func(T3) = T3 /* ERROR "not in method set" */ .p0 _ func(T3) = T3.p0 /* ERROR "not in method set" */
_ func(T3) = T3.v1 _ func(T3) = T3.v1
_ func(T3) = T3.p1 _ func(T3) = T3.p1
_ func(T3) = T3.v2 _ func(T3) = T3.v2
@ -135,7 +135,7 @@ func _() {
func _() { func _() {
var ( var (
_ func() = T0{}.v0 _ func() = T0{}.v0
_ func() = T0 /* ERROR "not in method set" */ {}.p0 _ func() = T0{}.p0 /* ERROR "not in method set" */
_ func() = (&T0{}).v0 _ func() = (&T0{}).v0
_ func() = (&T0{}).p0 _ func() = (&T0{}).p0
@ -145,7 +145,7 @@ func _() {
// no values for T2 // no values for T2
_ func() = T3{}.v0 _ func() = T3{}.v0
_ func() = T3 /* ERROR "not in method set" */ {}.p0 _ func() = T3{}.p0 /* ERROR "not in method set" */
_ func() = T3{}.v1 _ func() = T3{}.v1
_ func() = T3{}.p1 _ func() = T3{}.p1
_ func() = T3{}.v2 _ func() = T3{}.v2
@ -163,7 +163,7 @@ func _() {
// Method calls with value receivers // Method calls with value receivers
func _() { func _() {
T0{}.v0() T0{}.v0()
T0 /* ERROR "not in method set" */ {}.p0() T0{}.p0 /* ERROR "not in method set" */ ()
(&T0{}).v0() (&T0{}).v0()
(&T0{}).p0() (&T0{}).p0()
@ -173,7 +173,7 @@ func _() {
// no values for T2 // no values for T2
T3{}.v0() T3{}.v0()
T3 /* ERROR "not in method set" */ {}.p0() T3{}.p0 /* ERROR "not in method set" */ ()
T3{}.v1() T3{}.v1()
T3{}.p1() T3{}.p1()
T3{}.v2() T3{}.v2()
@ -196,9 +196,9 @@ func issue5918() {
_ func(error) string = error.Error _ func(error) string = error.Error
perr = &err perr = &err
_ = perr /* ERROR "no field or method" */ .Error() _ = perr.Error /* ERROR "no field or method" */ ()
_ func() string = perr /* ERROR "no field or method" */ .Error _ func() string = perr.Error /* ERROR "no field or method" */
_ func(*error) string = ( /* ERROR "no field or method" */ *error).Error _ func(*error) string = (*error).Error /* ERROR "no field or method" */
) )
type T *interface{ m() int } type T *interface{ m() int }
@ -207,8 +207,8 @@ func issue5918() {
_ = (*x).m() _ = (*x).m()
_ = (*x).m _ = (*x).m
_ = x /* ERROR "no field or method" */ .m() _ = x.m /* ERROR "no field or method" */ ()
_ = x /* ERROR "no field or method" */ .m _ = x.m /* ERROR "no field or method" */
_ = T /* ERROR "no field or method" */ .m _ = T.m /* ERROR "no field or method" */
) )
} }