Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: outer else falsely matched with inner if #2691

Open
fridis opened this issue Mar 8, 2024 · 0 comments · May be fixed by #3169
Open

parser: outer else falsely matched with inner if #2691

fridis opened this issue Mar 8, 2024 · 0 comments · May be fixed by #3169
Labels
bug Something isn't working enhancement New feature or request Fuzion language related to the language, syntax, etc parser related to the parser

Comments

@fridis
Copy link
Member

fridis commented Mar 8, 2024

This is related to #2371, another surprise: This example

for i in 1..10
do
  if i = 2 then say "A: found 2"
else
  say "A: done"

works as expected:

 > ./build//bin/fz test_loops.fz
A: found 2
A: done

while the same code with the if moved behind the do

for i in 1..10
do if i = 2 then say "B: found 2"
else
  say "B: done"

executes the else inside the loop as part of the if statment:

 > ./build//bin/fz test_loops2.fz
B: done
B: found 2
B: done
B: done
B: done
B: done
B: done
B: done
B: done
B: done

The same problem may occur with nested if statements:

if true
then if false then
else
  panic "*** unreachable ***"

which should not call panic, but it does:

 > ./build//bin/fz test_if.fz
*** panic: *** unreachable ***
@fridis fridis added bug Something isn't working enhancement New feature or request Fuzion language related to the language, syntax, etc parser related to the parser labels Mar 8, 2024
michaellilltokiwa added a commit to michaellilltokiwa/fuzion that referenced this issue Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request Fuzion language related to the language, syntax, etc parser related to the parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant