11

Why does the Delphi compiler ignore this missing parenthesis?

function Test: Boolean;
begin
  Exit(True;    // <-- eek! it compiles...
end;

I found some of my code looking like this and first thought that Delphi ignores my unit - but it just ignores this type of syntax error. So now of course I want to know why.

Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85

2 Answers2

1

I'm guessing Exit is considered a token unto itself, and as such anything defined within the same scope after Exit is simply ignored by the compiler (since it cannot execute those instructions anyway).

LaKraven
  • 5,804
  • 2
  • 23
  • 49
  • Adding instructions after the `Exit(True;` makes the compiler complain again with "E2066 Missing operator or semicolon" (Delphi XE). – Heinrich Ulbricht Apr 30 '12 at 08:30
  • I'd presume this is because the semicolon prompts the compiler to attempt to compile the next instruction. – LaKraven Apr 30 '12 at 08:32
  • Essentially I'm saying that `Exit` is an "absolute" token, prompting the compiler to disregard any subsequent chars on the same statement until the next occurence of the semicolon, which separates it from the proceeding instruction(s). It's a quirk, for sure... and an interesting find! – LaKraven Apr 30 '12 at 08:33
0

Maybe the compiler is thinking that either 1. There is an Exit by itself, or 2. There is an Exit with a set of parentheses (). If it doesn't find #2 it goes to #1.

Patrick Moloney
  • 642
  • 5
  • 14