mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-09-12 15:39:31 +00:00
reflect: implement Type.Overflow* functions
They're already implemented for the Value equivalents. But since Go 1.23, such methods also exist for reflect.Type.
This commit is contained in:
committed by
Ron Evans
parent
e865db232b
commit
e300e90a63
+40
-1
@@ -4897,7 +4897,7 @@ func TestComparable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverflow(t *testing.T) {
|
||||
func TestValueOverflow(t *testing.T) {
|
||||
if ovf := V(float64(0)).OverflowFloat(1e300); ovf {
|
||||
t.Errorf("%v wrongly overflows float64", 1e300)
|
||||
}
|
||||
@@ -4936,6 +4936,45 @@ func TestOverflow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTypeOverflow(t *testing.T) {
|
||||
if ovf := TypeFor[float64]().OverflowFloat(1e300); ovf {
|
||||
t.Errorf("%v wrongly overflows float64", 1e300)
|
||||
}
|
||||
|
||||
maxFloat32 := float64((1<<24 - 1) << (127 - 23))
|
||||
if ovf := TypeFor[float32]().OverflowFloat(maxFloat32); ovf {
|
||||
t.Errorf("%v wrongly overflows float32", maxFloat32)
|
||||
}
|
||||
ovfFloat32 := float64((1<<24-1)<<(127-23) + 1<<(127-52))
|
||||
if ovf := TypeFor[float32]().OverflowFloat(ovfFloat32); !ovf {
|
||||
t.Errorf("%v should overflow float32", ovfFloat32)
|
||||
}
|
||||
if ovf := TypeFor[float32]().OverflowFloat(-ovfFloat32); !ovf {
|
||||
t.Errorf("%v should overflow float32", -ovfFloat32)
|
||||
}
|
||||
|
||||
maxInt32 := int64(0x7fffffff)
|
||||
if ovf := TypeFor[int32]().OverflowInt(maxInt32); ovf {
|
||||
t.Errorf("%v wrongly overflows int32", maxInt32)
|
||||
}
|
||||
if ovf := TypeFor[int32]().OverflowInt(-1 << 31); ovf {
|
||||
t.Errorf("%v wrongly overflows int32", -int64(1)<<31)
|
||||
}
|
||||
ovfInt32 := int64(1 << 31)
|
||||
if ovf := TypeFor[int32]().OverflowInt(ovfInt32); !ovf {
|
||||
t.Errorf("%v should overflow int32", ovfInt32)
|
||||
}
|
||||
|
||||
maxUint32 := uint64(0xffffffff)
|
||||
if ovf := TypeFor[uint32]().OverflowUint(maxUint32); ovf {
|
||||
t.Errorf("%v wrongly overflows uint32", maxUint32)
|
||||
}
|
||||
ovfUint32 := uint64(1 << 32)
|
||||
if ovf := TypeFor[uint32]().OverflowUint(ovfUint32); !ovf {
|
||||
t.Errorf("%v should overflow uint32", ovfUint32)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
func checkSameType(t *testing.T, x Type, y any) {
|
||||
|
||||
Reference in New Issue
Block a user