fuzion
fuzion copied to clipboard
Argument type inference is fairly dumb, could join `String` and `codepoint` into `String
Take this example
# function with 3 arguments of inferred type i32, codepoint and codepoint:
#
line(l, start, end) =>
start + "-"*l + end
line 20 "<" ">" |> say
line 10 "<<" ">>" |> say
Which produces
> ../build/bin/fz content/tutorial/examples/value_args_example2infer_fail.fz
/home/fridi/fuzion/work/webserver/content/tutorial/examples/value_args_example2infer_fail.fz:7:9: error 1: Incompatible types when passing argument in a call
line 10 "<<" ">>" |> say
Actual type for argument #2 'start' does not match expected type.
In call to : 'line'
expected formal type: 'codepoint'
actual type found : 'String'
assignable to : 'String'
for value assigned : '"<<"'
To solve this, you could change the type of the target 'start' to 'String' or convert the type of the assigned value to 'codepoint'.
/home/fridi/fuzion/work/webserver/content/tutorial/examples/value_args_example2infer_fail.fz:7:14: error 2: Incompatible types when passing argument in a call
line 10 "<<" ">>" |> say
Actual type for argument #3 'end' does not match expected type.
In call to : 'line'
expected formal type: 'codepoint'
actual type found : 'String'
assignable to : 'String'
for value assigned : '">>"'
To solve this, you could change the type of the target 'end' to 'String' or convert the type of the assigned value to 'codepoint'.
2 errors.
while it works if the calls are swapped
# function with 3 arguments of inferred type i32, codepoint and codepoint:
#
line(l, start, end) =>
start + "-"*l + end
line 10 "<<" ">>" |> say
line 20 "<" ">" |> say
It would be nice to either produce an error independently of the the order, or not to produce an error at all.
@fridis Just to clarify, a union of array and list would still not be Sequence but t_error, right?