Skip to content

Commit e46adc1

Browse files
committed
Fixes for int and byte tests
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
1 parent 3e242eb commit e46adc1

5 files changed

Lines changed: 996 additions & 867 deletions

File tree

pkg/lang/numbers.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,15 +786,27 @@ func BooleanCast(x any) bool {
786786
return !IsNil(x)
787787
}
788788

789-
func ByteCast(x any) byte {
790-
if b, ok := x.(byte); ok {
791-
return b
789+
func ByteCast(x any) int8 {
790+
switch x := x.(type) {
791+
case int8:
792+
return x
793+
case float32:
794+
if x < math.MinInt8 || x > math.MaxInt8 {
795+
panic(fmt.Errorf("value out of range for byte: %v", x))
796+
}
797+
return int8(x)
798+
case float64:
799+
if x < math.MinInt8 || x > math.MaxInt8 {
800+
panic(fmt.Errorf("value out of range for byte: %v", x))
801+
}
802+
return int8(x)
792803
}
804+
793805
l := AsInt64(x)
794806
if l < math.MinInt8 || l > math.MaxInt8 {
795807
panic(fmt.Errorf("value out of range for byte: %v", x))
796808
}
797-
return byte(l)
809+
return int8(l)
798810
}
799811

800812
func UncheckedByteCast(x any) byte {

pkg/runtime/rtcompat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (rt *RTMethods) BooleanCast(x any) bool {
102102
return lang.BooleanCast(x)
103103
}
104104

105-
func (rt *RTMethods) ByteCast(x any) byte {
105+
func (rt *RTMethods) ByteCast(x any) int8 {
106106
return lang.ByteCast(x)
107107
}
108108

pkg/stdlib/clojure/core.glj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,10 +1397,7 @@
13971397
(defn int?
13981398
"Return true if x is a fixed precision integer"
13991399
{:added "1.9"}
1400-
[x] (or (instance? go/int64 x)
1401-
(instance? Integer x)
1402-
(instance? Short x)
1403-
(instance? Byte x)))
1400+
[x] (or (instance? go/int x) (instance? go/uint x) (instance? go/byte x) (instance? go/int64 x) (instance? go/int32 x) (instance? go/int16 x) (instance? go/int8 x) (instance? go/uint64 x) (instance? go/uint32 x) (instance? go/uint16 x) (instance? go/uint8 x)))
14041401

14051402
(defn pos-int?
14061403
"Return true if x is a positive fixed precision integer"

0 commit comments

Comments
 (0)