File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 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) {
612612 })
613613 }
614614}
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 {
209209 }
210210 return i
211211 default :
212+ val := reflect .ValueOf (x )
213+ if val .CanConvert (integerType ) {
214+ return val .Convert (integerType ).Interface ()
215+ }
212216 panic (fmt .Sprintf ("invalid operation: int(%T)" , x ))
213217 }
214218}
You can’t perform that action at this time.
0 commit comments