Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2019-09

Case else allows multiple statements

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Kirinn

I've stumbled on a situation where a case statement compiles when I wouldn't expect it to. I would expect the below code to produce a compile error:

     program test;
     var i : byte = 5;

    begin

         case i of
             0..4: writeln('value is ', i);
             else writeln('Else!');
             i := 3;
             writeln(i);
         end;

    end.

This compiles without errors or warnings on FPC 3.0.4 and produces the output:

    Else!

    3

None of the documentation I've looked at suggests that a case-else is implicitly a block. All examples in the documentation show only a single statement in any else clause, or an explicit begin-end block.

Is this expected behavior? If yes, the reference guide (13.2.2) would benefit from mentioning this.

~Kirinn

Reply by email

Sven Barth
to Kirinn
Kirinn wrote 37 lines
I've stumbled on a situation where a case statement compiles when I wouldn't expect it to. I would expect the below code to produce a compile error:     program test;     var i : byte = 5;     begin         case i of             0..4: writeln('value is ', i);             else writeln('Else!');             i := 3;             writeln(i);         end;     end. This compiles without errors or warnings on FPC 3.0.4 and produces the output:     Else!     3 None of the documentation I've looked at suggests that a case-else is implicitly a block. All examples in the documentation show only a single statement in any else clause, or an explicit begin-end block. Is this expected behavior? If yes, the reference guide (13.2.2) would benefit from mentioning this.

That is indeed by design (at least Delphi compiles it as well). You can file a bug report against the documentation so that it isn't forgotten.

Regards,
Sven

Reply by email

Alexander Grotewohl
to Sven Barth

I'm assuming that's what the 'statementlist' means in the documentation (rather than just 'statement')

Sven Barth wrote 47 lines
Am 19.09.2019 um 21:07 schrieb Kirinn: > I've stumbled on a situation where a case statement compiles when I > wouldn't expect it to. I would expect the below code to produce a > compile error: > >     program test; > >     var i : byte = 5; > >     begin > >         case i of > >             0..4: writeln('value is ', i); > >             else writeln('Else!'); > >             i := 3; > >             writeln(i); > >         end; > >     end. > > This compiles without errors or warnings on FPC 3.0.4 and produces > the output: > >     Else! > >     3 > > None of the documentation I've looked at suggests that a case-else is > implicitly a block. All examples in the documentation show only a > single statement in any else clause, or an explicit begin-end block. > > Is this expected behavior? If yes, the reference guide (13.2.2) would > benefit from mentioning this. That is indeed by design (at least Delphi compiles it as well). You can file a bug report against the documentation so that it isn't forgotten. Regards, Sven _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Kirinn
to Alexander Grotewohl

Thanks, I've added a minor doc bug for it.

https://bugs.freepascal.org/view.php?id=36090

Alexander Grotewohl wrote 54 lines
I'm assuming that's what the 'statementlist' means in the documentation (rather than just 'statement') On 9/19/2019 3:33 PM, Sven Barth via fpc-devel wrote: > Am 19.09.2019 um 21:07 schrieb Kirinn: >> I've stumbled on a situation where a case statement compiles when I >> wouldn't expect it to. I would expect the below code to produce a >> compile error: >> >>     program test; >> >>     var i : byte = 5; >> >>     begin >> >>         case i of >> >>             0..4: writeln('value is ', i); >> >>             else writeln('Else!'); >> >>             i := 3; >> >>             writeln(i); >> >>         end; >> >>     end. >> >> This compiles without errors or warnings on FPC 3.0.4 and produces >> the output: >> >>     Else! >> >>     3 >> >> None of the documentation I've looked at suggests that a case-else >> is implicitly a block. All examples in the documentation show only a >> single statement in any else clause, or an explicit begin-end block. >> >> Is this expected behavior? If yes, the reference guide (13.2.2) >> would benefit from mentioning this. > That is indeed by design (at least Delphi compiles it as well). You > can file a bug report against the documentation so that it isn't > forgotten. > > Regards, > Sven > _______________________________________________ > fpc-devel maillist  -  > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email