Closed gbouv closed 1 year ago
int and float are distinct types in Starlark, so this is working as intended. If you want your function to accept either type, then use var x any; UnpackArgs(..., &x)
and then do a type-switch on x. Or define a custom IntOrFloat type that defines the Unpack method and pass a variable of that type to UnpackArgs.
I have a custom builtin which expects a float argument. When I write my Starlark, I would like to be able to input a simple integer. Sometimes, I don't care about digits after the decimal point, and I would expect the interpreter to safely assume
50=50.0
. Currently, the interpreter crashes with "got int, want float".Simple repro:
The above works fine when
float_arg=50.0
but throws an error whenfloat_arg=50
, which is a bit misleadingDoes that look like a reasonable change? I can try to look into it. I looked at
UnpackArgs
as well as theFloat
andInt
but I am not sure what could be changed to allow this. Do you have some guidance?