[fpc-devel] Case else allows multiple statements

Kirinn kirinn at mooncore.eu
Thu Sep 19 21:07:25 CEST 2019


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



More information about the fpc-devel mailing list