mirror of https://github.com/golang/go.git
65 lines
1.9 KiB
Plaintext
65 lines
1.9 KiB
Plaintext
// 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
|
|
|
|
func F1[T comparable]() {}
|
|
func F2() { F1[[]int]() } // ERROR "\[\]int does not satisfy comparable$"
|
|
|
|
type C interface {
|
|
M()
|
|
}
|
|
|
|
func F3[T C]() {}
|
|
func F4() { F3[int]() } // ERROR "int does not satisfy C.*method M"
|
|
|
|
func F5[T any]() { F3[T]() } // ERROR "T does not satisfy C.*method M"
|
|
|
|
type signed interface {
|
|
type int, int8, int16, int32, int64
|
|
}
|
|
|
|
type integer interface {
|
|
type int, int8, int16, int32, int64,
|
|
uint, uint8, uint16, uint32, uint64, uintptr
|
|
}
|
|
|
|
func F6[T signed](a T) bool { return a < 0 }
|
|
func F7[T any](a T) bool { return F6(a) } // ERROR "T does not satisfy signed.*T has no type constraints"
|
|
func F8[T integer](a T) bool { return F6(a) } // ERROR "T does not satisfy signed.*T type constraint uint not found in"
|
|
func F9(a uint) bool { return F6(a) } // ERROR "uint does not satisfy signed.*uint not found in"
|
|
|
|
type MyInt int
|
|
type MyUint uint
|
|
|
|
func F10(a MyInt) bool { return F6(a) }
|
|
func F11(a MyUint) bool { return F6(a) } // ERROR "MyUint does not satisfy signed.*uint not found in"
|
|
|
|
type C2 interface {
|
|
C
|
|
signed
|
|
}
|
|
|
|
func F20[T C2](a T) bool {
|
|
a.M()
|
|
return a < 0
|
|
}
|
|
|
|
func (MyInt) M() {}
|
|
|
|
func (MyUint) M() {}
|
|
|
|
type S struct {}
|
|
func (S) M() {}
|
|
|
|
func F21() bool { return F20(MyInt(0)) }
|
|
func F22() bool { return F20(0) } // ERROR "int does not satisfy C2.*(missing method M)"
|
|
func F23[T any](a T) bool { return F20(a) } // ERROR "T does not satisfy C2.*(missing method M)"
|
|
func F24[T integer](a T) bool { return F20(a) } // ERROR "T does not satisfy C2.*(missing method M)"
|
|
func F25(a uint) bool { return F20(a) } // ERROR "uint does not satisfy C2.*(missing method M)"
|
|
func F26(a MyUint) bool { return F20(a) } // ERROR "MyUint does not satisfy C2.*uint not found in"
|
|
func F27(a S) bool { return F20(a) } // ERROR "S does not satisfy C2.*struct{} not found in"
|