File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -612,3 +612,17 @@ func TestBuiltin_bitOpsFunc(t *testing.T) {
612
612
})
613
613
}
614
614
}
615
+
616
+ type customInt int
617
+
618
+ func Test_int_unwraps_underlying_value (t * testing.T ) {
619
+ env := map [string ]any {
620
+ "customInt" : customInt (42 ),
621
+ }
622
+ program , err := expr .Compile (`int(customInt) == 42` , expr .Env (env ))
623
+ require .NoError (t , err )
624
+
625
+ out , err := expr .Run (program , env )
626
+ require .NoError (t , err )
627
+ assert .Equal (t , true , out )
628
+ }
Original file line number Diff line number Diff line change @@ -209,6 +209,10 @@ func Int(x any) any {
209
209
}
210
210
return i
211
211
default :
212
+ val := reflect .ValueOf (x )
213
+ if val .CanConvert (integerType ) {
214
+ return val .Convert (integerType ).Interface ()
215
+ }
212
216
panic (fmt .Sprintf ("invalid operation: int(%T)" , x ))
213
217
}
214
218
}
You can’t perform that action at this time.
0 commit comments