| 1 |
[short] skip |
| 2 |
[!cgo] skip |
| 3 |
|
| 4 |
# Test that cgo rejects attempts to declare methods |
| 5 |
# on the types C.T or *C.T; see issue #57926. |
| 6 |
|
| 7 |
! go build |
| 8 |
stderr 'cannot define new methods on non-local type C.T' |
| 9 |
stderr 'cannot define new methods on non-local type \*C.T' |
| 10 |
! stderr 'Alias' |
| 11 |
|
| 12 |
-- go.mod -- |
| 13 |
module example.com |
| 14 |
go 1.12 |
| 15 |
|
| 16 |
-- a.go -- |
| 17 |
package a |
| 18 |
|
| 19 |
/* |
| 20 |
typedef int T; |
| 21 |
*/ |
| 22 |
import "C" |
| 23 |
|
| 24 |
func (C.T) f() {} |
| 25 |
func (recv *C.T) g() {} |
| 26 |
|
| 27 |
// The check is more education than enforcement, |
| 28 |
// and is easily defeated using a type alias. |
| 29 |
type Alias = C.T |
| 30 |
func (Alias) h() {} |
| 31 |
func (*Alias) i() {} |