mirror of
https://github.com/golang/go
synced 2024-11-22 10:44:41 -07:00
0c1a899a6c
The compiler has logic to check whether we implicitly dereferenced a defined pointer while trying to select a method. However, rather than checking whether there were any implicit dereferences of a defined pointer, it was finding the innermost dereference/selector expression and checking whether that was dereferencing a named pointer. Moreover, it was only checking defined pointer declared in the package block. This CL restructures the code to match go/types and gccgo's behavior. Fixes #43384. Change-Id: I7bddfe2515776d9480eb2c7286023d4c15423888 Reviewed-on: https://go-review.googlesource.com/c/go/+/280392 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
125 lines
1.9 KiB
Go
125 lines
1.9 KiB
Go
// errorcheck
|
|
|
|
// Copyright 2020 The Go Authors. All rights reserved. Use of this
|
|
// source code is governed by a BSD-style license that can be found in
|
|
// the LICENSE file.
|
|
|
|
package p
|
|
|
|
type T int
|
|
|
|
func (T) Mv() {}
|
|
func (*T) Mp() {}
|
|
|
|
type P1 struct{ T }
|
|
type P2 struct{ *T }
|
|
type P3 *struct{ T }
|
|
type P4 *struct{ *T }
|
|
|
|
func _() {
|
|
{
|
|
var p P1
|
|
p.Mv()
|
|
(&p).Mv()
|
|
(*&p).Mv()
|
|
p.Mp()
|
|
(&p).Mp()
|
|
(*&p).Mp()
|
|
}
|
|
{
|
|
var p P2
|
|
p.Mv()
|
|
(&p).Mv()
|
|
(*&p).Mv()
|
|
p.Mp()
|
|
(&p).Mp()
|
|
(*&p).Mp()
|
|
}
|
|
{
|
|
var p P3
|
|
p.Mv() // ERROR "undefined"
|
|
(&p).Mv() // ERROR "undefined"
|
|
(*&p).Mv() // ERROR "undefined"
|
|
(**&p).Mv()
|
|
(*p).Mv()
|
|
(&*p).Mv()
|
|
p.Mp() // ERROR "undefined"
|
|
(&p).Mp() // ERROR "undefined"
|
|
(*&p).Mp() // ERROR "undefined"
|
|
(**&p).Mp()
|
|
(*p).Mp()
|
|
(&*p).Mp()
|
|
}
|
|
{
|
|
var p P4
|
|
p.Mv() // ERROR "undefined"
|
|
(&p).Mv() // ERROR "undefined"
|
|
(*&p).Mv() // ERROR "undefined"
|
|
(**&p).Mv()
|
|
(*p).Mv()
|
|
(&*p).Mv()
|
|
p.Mp() // ERROR "undefined"
|
|
(&p).Mp() // ERROR "undefined"
|
|
(*&p).Mp() // ERROR "undefined"
|
|
(**&p).Mp()
|
|
(*p).Mp()
|
|
(&*p).Mp()
|
|
}
|
|
}
|
|
|
|
func _() {
|
|
type P5 struct{ T }
|
|
type P6 struct{ *T }
|
|
type P7 *struct{ T }
|
|
type P8 *struct{ *T }
|
|
|
|
{
|
|
var p P5
|
|
p.Mv()
|
|
(&p).Mv()
|
|
(*&p).Mv()
|
|
p.Mp()
|
|
(&p).Mp()
|
|
(*&p).Mp()
|
|
}
|
|
{
|
|
var p P6
|
|
p.Mv()
|
|
(&p).Mv()
|
|
(*&p).Mv()
|
|
p.Mp()
|
|
(&p).Mp()
|
|
(*&p).Mp()
|
|
}
|
|
{
|
|
var p P7
|
|
p.Mv() // ERROR "undefined"
|
|
(&p).Mv() // ERROR "undefined"
|
|
(*&p).Mv() // ERROR "undefined"
|
|
(**&p).Mv()
|
|
(*p).Mv()
|
|
(&*p).Mv()
|
|
p.Mp() // ERROR "undefined"
|
|
(&p).Mp() // ERROR "undefined"
|
|
(*&p).Mp() // ERROR "undefined"
|
|
(**&p).Mp()
|
|
(*p).Mp()
|
|
(&*p).Mp()
|
|
}
|
|
{
|
|
var p P8
|
|
p.Mv() // ERROR "undefined"
|
|
(&p).Mv() // ERROR "undefined"
|
|
(*&p).Mv() // ERROR "undefined"
|
|
(**&p).Mv()
|
|
(*p).Mv()
|
|
(&*p).Mv()
|
|
p.Mp() // ERROR "undefined"
|
|
(&p).Mp() // ERROR "undefined"
|
|
(*&p).Mp() // ERROR "undefined"
|
|
(**&p).Mp()
|
|
(*p).Mp()
|
|
(&*p).Mp()
|
|
}
|
|
}
|