| 1 |
package pkg |
| 2 |
|
| 3 |
import "math" |
| 4 |
|
| 5 |
func fn1[T uint8 | uint16](x T) { |
| 6 |
_ = x >= 0 //@ diag(`every value of type T is >= 0`) |
| 7 |
_ = x < 0 //@ diag(`no value of type T is less than 0`) |
| 8 |
|
| 9 |
// No diagnostic, T has multiple sizes |
| 10 |
_ = x > math.MaxUint8 |
| 11 |
} |
| 12 |
|
| 13 |
func fn2[T uint8 | int8](x T) { |
| 14 |
// No diagnostics, no common signedness or size |
| 15 |
_ = x >= 0 |
| 16 |
_ = x < 0 |
| 17 |
} |
| 18 |
|
| 19 |
func fn3[T uint8](x T) { |
| 20 |
_ = x >= 0 //@ diag(`every value of type T is >= 0`) |
| 21 |
_ = x < 0 //@ diag(`no value of type T is less than 0`) |
| 22 |
_ = x > math.MaxUint8 //@ diag(`no value of type T is greater than math.MaxUint8`) |
| 23 |
} |
| 24 |
|
| 25 |
func fn4[T ~uint8](x T) { |
| 26 |
_ = x >= 0 //@ diag(`every value of type T is >= 0`) |
| 27 |
_ = x < 0 //@ diag(`no value of type T is less than 0`) |
| 28 |
_ = x > math.MaxUint8 //@ diag(`no value of type T is greater than math.MaxUint8`) |
| 29 |
} |
| 30 |
|
| 31 |
type ( |
| 32 |
U1 uint8 |
| 33 |
U2 uint8 |
| 34 |
) |
| 35 |
|
| 36 |
func fn5[T U1 | U2](x T) { |
| 37 |
_ = x >= 0 //@ diag(`every value of type T is >= 0`) |
| 38 |
_ = x < 0 //@ diag(`no value of type T is less than 0`) |
| 39 |
_ = x > math.MaxUint8 //@ diag(`no value of type T is greater than math.MaxUint8`) |
| 40 |
} |
| 41 |
|
| 42 |
type S[T uint8 | uint16] struct { |
| 43 |
f T |
| 44 |
} |
| 45 |
|
| 46 |
func (s S[T]) fn6() { |
| 47 |
_ = s.f >= 0 //@ diag(`every value of type T is >= 0`) |
| 48 |
_ = s.f < 0 //@ diag(`no value of type T is less than 0`) |
| 49 |
|
| 50 |
// No diagnostic, T has multiple sizes |
| 51 |
_ = s.f > math.MaxUint8 |
| 52 |
} |
| 53 |
|
| 54 |
func (s S[T]) fn7(x T) { |
| 55 |
_ = x >= 0 //@ diag(`every value of type T is >= 0`) |
| 56 |
_ = x < 0 //@ diag(`no value of type T is less than 0`) |
| 57 |
|
| 58 |
// No diagnostic, T has multiple sizes |
| 59 |
_ = x > math.MaxUint8 |
| 60 |
} |