fuzion
fuzion copied to clipboard
AoC: Different handling of indentation of code in `()` vs `{}` is confusing
I ran into this during 6 dec 24 Advent of Code:
This code
ignore i32->bool p->{if p = 3 then
say "hi"
false}
works as expected
> ~/fuzion/work/build/bin/fz indentation_error3.fz
while the same code using ()
ignore i32->bool p->(if p = 3 then
say "hi"
false)
fails parsing and produced indentation errors and type errors caused by the parser producing a wrong AST:
> ~/fuzion/work/build/bin/fz indentation_error2.fz
/home/fridi/fuzion/advent_of_code/fuzion_aoc/2024/06/indentation_error2.fz:3:22: error 1: Inconsistent indentation
false)
Indentation reference point is /home/fridi/fuzion/advent_of_code/fuzion_aoc/2024/06/indentation_error2.fz:1:22:
ignore i32->bool p->(if p = 3 then
While parsing: klammer, parse stack: klammer, bracketTerm, term, opTail, opExpr, operatorExpr (twice), expr, exprs, block (twice), lambda, plainLambda, callOrFeatOrThis, term, opTail, opExpr, operatorExpr (twice), actualSpace, actualSpaces, actualArgs, call (twice), callOrFeatOrThis, term, opTail, opExpr, operatorExpr (twice), expr, exprs, block (twice), unit
/home/fridi/fuzion/advent_of_code/fuzion_aoc/2024/06/indentation_error2.fz:2:24: error 2: Incompatible types in assignment
say "hi"
assignment to field : 'λ.call.result'
expected formal type: 'bool'
actual type found : 'unit'
assignable to : 'unit'
for value assigned : 'say "hi"'
To solve this, you could change the type of the target 'λ.call.result' to 'unit' or convert the type of the assigned value to 'bool'.
/home/fridi/fuzion/advent_of_code/fuzion_aoc/2024/06/indentation_error2.fz:1:22: error 3: Incompatible types in assignment
ignore i32->bool p->(if p = 3 then
assignment to field : 'λ.call.result'
expected formal type: 'bool'
actual type found : 'unit'
assignable to : 'unit'
for value assigned : ''
To solve this, you could change the type of the target 'λ.call.result' to 'unit' or convert the type of the assigned value to 'bool'.
3 errors.
see also #2283