mirror of
https://github.com/golang/go
synced 2024-11-17 14:34:46 -07:00
91803a2df3
The following files had merge conflicts and were merged manually: src/cmd/compile/fmtmap_test.go src/cmd/compile/internal/gc/noder.go src/go/parser/error_test.go test/assign.go test/chan/perm.go test/fixedbugs/issue22822.go test/fixedbugs/issue4458.go test/init.go test/interface/explicit.go test/map1.go test/method2.go The following files had manual changes to make tests pass: test/run.go test/used.go src/cmd/compile/internal/types2/stdlib_test.go Change-Id: Ia495aaaa80ce321ee4ec2a9105780fbe913dbd4c
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"
|
|
|
|
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"
|