fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

lambda result type mismatch does not cause type inference

Open maxteufel opened this issue 3 months ago • 0 comments

this small example currently causes an incompatible types in assignment error

$ cat ex_stopwatch_inference.fz
ex_stopwatch_inference =>
  r, t := time.stopwatch ()->
    String.from_bytes [0x61]

  say r
  say t
$ fz ex_stopwatch_inference.fz

ex_stopwatch_inference.fz:2:8: error 1: Destructuring mismatch between number of visible fields and number of target variables.
  r, t := time.stopwatch ()->

Found one visible argument field
while there are 2 destructuring variables.


ex_stopwatch_inference.fz:3:12: error 2: Incompatible types in assignment
    String.from_bytes [0x61]

assignment to field : 'ex_stopwatch_inference.λ.call.result'
expected formal type: 'unit'
actual type found   : 'String'
assignable to       : 'String'
for value assigned  : 'String.from_bytes [0x61]'
To solve this, you could explicitly ignore the result of the last expression by an assignment '_ := <expression>'.

2 errors.

(and as a result also the first error)

what I would expect is that this automatically infers the other variant time.stopwatch String lambda

maxteufel avatar Oct 07 '25 14:10 maxteufel