@@ -34,7 +34,7 @@ var Builtins = map[int]*Function{
3434 if len (args ) != 1 {
3535 return anyType , fmt .Errorf ("invalid number of arguments for len (expected 1, got %d)" , len (args ))
3636 }
37- switch args [0 ]. Kind ( ) {
37+ switch kind ( args [0 ]) {
3838 case reflect .Array , reflect .Map , reflect .Slice , reflect .String , reflect .Interface :
3939 return integerType , nil
4040 }
@@ -48,7 +48,7 @@ var Builtins = map[int]*Function{
4848 if len (args ) != 1 {
4949 return anyType , fmt .Errorf ("invalid number of arguments for abs (expected 1, got %d)" , len (args ))
5050 }
51- switch args [0 ]. Kind ( ) {
51+ switch kind ( args [0 ]) {
5252 case reflect .Float32 , reflect .Float64 , reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 , reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 , reflect .Interface :
5353 return args [0 ], nil
5454 }
@@ -62,7 +62,7 @@ var Builtins = map[int]*Function{
6262 if len (args ) != 1 {
6363 return anyType , fmt .Errorf ("invalid number of arguments for int (expected 1, got %d)" , len (args ))
6464 }
65- switch args [0 ]. Kind ( ) {
65+ switch kind ( args [0 ]) {
6666 case reflect .Interface :
6767 return integerType , nil
6868 case reflect .Float32 , reflect .Float64 , reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 , reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 :
@@ -80,7 +80,7 @@ var Builtins = map[int]*Function{
8080 if len (args ) != 1 {
8181 return anyType , fmt .Errorf ("invalid number of arguments for float (expected 1, got %d)" , len (args ))
8282 }
83- switch args [0 ]. Kind ( ) {
83+ switch kind ( args [0 ]) {
8484 case reflect .Interface :
8585 return floatType , nil
8686 case reflect .Float32 , reflect .Float64 , reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 , reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 :
@@ -92,3 +92,10 @@ var Builtins = map[int]*Function{
9292 },
9393 },
9494}
95+
96+ func kind (t reflect.Type ) reflect.Kind {
97+ if t == nil {
98+ return reflect .Invalid
99+ }
100+ return t .Kind ()
101+ }
0 commit comments