fuzion
fuzion copied to clipboard
`Any.dynamic_apply` cannot be called with a lambda
Take this exmaple that is a based on the code given in #5896:
sum(values Sequence Any)
=>
values.map a->
a.dynamic_apply T,v->
if T : i32 then v.as_f64
else if T : f64 then v.val
else compile_time_panic
.foldf 0.0 (+)
say <| sum [3.14, 32, 16.0, 8]
It creates two errors:
> ../build/bin/fz ../dyn_apply.fz
/home/fridi/fuzion/work/webserver/../dyn_apply.fz:4:27: error 1: Failed to infer actual type parameters
a.dynamic_apply T,v->
if T : i32 then v.as_f64
else if T : f64 then v.val
else compile_time_panic
In call to 'Typed_Function', no actual type parameters are given and inference of the type parameters failed.
Expected type parameters: 'R, A...'
Type inference failed for one type parameter 'R'
/home/fridi/fuzion/work/webserver/../dyn_apply.fz:4:27: error 2: Incompatible types when passing argument in a call
a.dynamic_apply T,v->
if T : i32 then v.as_f64
else if T : f64 then v.val
else compile_time_panic
Actual type for argument #1 'f' does not match expected type.
In call to : 'Any.dynamic_apply'
expected formal type: 'Typed_Function R'
actual type found : 'sum.λ.call.this.λ'
assignable to : '**error**',
'sum.λ.call.this.λ'
for value assigned :
T,v->
if T : i32 then v.as_f64
else if T : f64 then v.val
else compile_time_panic
To solve this, you could change the type of the target 'f' to 'sum.λ.call.this.λ' or convert the type of the assigned value to 'Typed_Function R'.
2 errors.
The second error should be suppressed since it is a result only of the previous error.
But the first error should be fixed by supporting type inference for R.