mirror of https://github.com/golang/go.git
go/types: must have at least one type when checking type list properties
Fixes bug with generic min being accepted even though the contract or interface bound doesn't enumerate any types (or is missing). Change-Id: Icdfc62fbd2b73ece397d5b5f1ebe27e52ed9b32f
This commit is contained in:
parent
32c4c5a5f8
commit
3fd481043b
|
|
@ -37,15 +37,25 @@ func swapswap(type A, B)(a A, b B) (A, B) {
|
|||
return swap(B, A)(b, a)
|
||||
}
|
||||
|
||||
// type F(type A, B) func(A, B) (B, A)
|
||||
type F(type A, B) func(A, B) (B, A)
|
||||
|
||||
func min(type T)(x, y T) T {
|
||||
//if x < y {
|
||||
// return x
|
||||
//}
|
||||
func min(type T interface{ type int })(x, y T) T {
|
||||
if x < y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
func _(type T interface{type int, float32})(x, y T) bool { return x < y }
|
||||
func _(type T)(x, y T) bool { return x /* ERROR cannot compare */ < y }
|
||||
func _(type T interface{type int, float32, bool})(x, y T) bool { return x /* ERROR cannot compare */ < y }
|
||||
|
||||
func _(type T C1)(x, y T) bool { return x /* ERROR cannot compare */ < y }
|
||||
func _(type T C2)(x, y T) bool { return x < y }
|
||||
|
||||
contract C1(T) {}
|
||||
contract C2(T) { T int, float32 }
|
||||
|
||||
func new(type T)() *T {
|
||||
var x T
|
||||
return &x
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ func (t *Interface) is(pred func(Type) bool) bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return len(t.allTypes) > 0 // we must have at least one type! (was bug)
|
||||
}
|
||||
|
||||
// emptyInterface represents the empty (completed) interface
|
||||
|
|
|
|||
Loading…
Reference in New Issue