Skip to content

Commit

Permalink
Type apply attempts coercion if simple conversion doesn't work
Browse files Browse the repository at this point in the history
Signed-off-by: James Hamlin <[email protected]>
  • Loading branch information
jfhamlin committed Oct 1, 2023
1 parent 7b5b420 commit 646b6e0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/lang/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ func applyType(typ reflect.Type, args []interface{}) interface{} {
arg := args[0]
argVal := reflect.ValueOf(arg)
if !argVal.CanConvert(typ) {
panic(NewIllegalArgumentError(fmt.Sprintf("cannot convert %T to %s", arg, typ)))
// try coercing the argument to the target type
coerced, err := coerceGoValue(typ, arg)
if err != nil {
panic(NewIllegalArgumentError(fmt.Sprintf("cannot convert %T to %s", arg, typ)))
}
return coerced.Interface()
}
return argVal.Convert(typ).Interface()
}
Expand Down

0 comments on commit 646b6e0

Please sign in to comment.