mirror of
https://github.com/golang/go
synced 2024-11-23 20:20:01 -07:00
6019a52d4d
- detect *interface case and report specific error - replaced switch with sequence of if's for more clarity - fixed isInterfacePtr: it applies to all interfaces, incl. type parameters - reviewed/fixed all uses of isInterfacePtr - adjusted error messages to be consistently of the format "type %s is pointer to interface, not interface" Fixes #48312. Change-Id: Ic3c8cfcf93ad57ecdb60f6a727cce9e1aa4afb5d Reviewed-on: https://go-review.googlesource.com/c/go/+/376914 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
// errorcheck
|
|
|
|
// Copyright 2009 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.
|
|
|
|
// Verify that pointers and interface types cannot be method receivers.
|
|
// Does not compile.
|
|
|
|
package main
|
|
|
|
type T struct {
|
|
a int
|
|
}
|
|
type P *T
|
|
type P1 *T
|
|
|
|
func (p P) val() int { return 1 } // ERROR "receiver.* pointer|invalid pointer or interface receiver|invalid receiver"
|
|
func (p *P1) val() int { return 1 } // ERROR "receiver.* pointer|invalid pointer or interface receiver|invalid receiver"
|
|
|
|
type I interface{}
|
|
type I1 interface{}
|
|
|
|
func (p I) val() int { return 1 } // ERROR "receiver.*interface|invalid pointer or interface receiver"
|
|
func (p *I1) val() int { return 1 } // ERROR "receiver.*interface|invalid pointer or interface receiver"
|
|
|
|
type Val interface {
|
|
val() int
|
|
}
|
|
|
|
var _ = (*Val).val // ERROR "method|type \*Val is pointer to interface, not interface"
|
|
|
|
var v Val
|
|
var pv = &v
|
|
|
|
var _ = pv.val() // ERROR "undefined|pointer to interface"
|
|
var _ = pv.val // ERROR "undefined|pointer to interface"
|
|
|
|
func (t *T) g() int { return t.a }
|
|
|
|
var _ = (T).g() // ERROR "needs pointer receiver|undefined|method requires pointer|cannot call pointer method"
|