Guess the output of this program.
Is this three Delphi bugs for the price of one?
Compiler mentions:
[dcc32 Hint] WeirdCaseConstruct.dpr(11): H2077 Value assigned to ‘Handled’ never used
1. If statement inside case – after ELSE option?
2. Handled is actually used
3. else Test(4) is never called
#wtf XE7.1 (32-bit, Windows)
program WeirdCaseConstruct;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
procedure Test(const Value: Integer);
var
Handled: Boolean;
begin
Handled := True; // <- Hinted
case Value of
1: writeln(‘One’);
2: writeln(‘Two’);
else Handled := False;
if not Handled
then Writeln(Value, ‘ is unhandled’)
else Test(4);
end;
end;
begin
Test(1);
Test(3);
Write(‘Press Enter’);
Readln;
end.
You must be logged in to post a comment.