Recent

Author Topic: Unexpected lack of error message  (Read 436 times)

440bx

  • Hero Member
  • *****
  • Posts: 5880
Unexpected lack of error message
« on: November 08, 2025, 09:59:06 pm »
Hello,

Consider the following code:
Code: Pascal  [Select][+][-]
  1. program NoErrorOnMissingOp;
  2.  
  3. const
  4.  a = 1;
  5.  b = 2;
  6.  c = 3;
  7.  
  8. {$if
  9.      (a <> 1)
  10.      (b <> 0) or
  11.      (c <> 3)
  12. }
  13.    {$MESSAGE 'a message here'}
  14. {$endif}
  15.  
  16. var
  17.   v : integer;
  18.  
  19. begin
  20.   v := a + b + c;
  21.  
  22.   readln;
  23. end.  
  24.  
Note the missing operator ("or" in this case) on line 9.  The compiler does not emit a message about the missing operator.  Of course, as a result, the expression does not work as expected, i.e, no message is displayed.

It would have been nice for the compiler to emit some sort of message about a "likely" missing operator.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18475
  • Here stood a man who saw the Elbe and jumped it.
Re: Unexpected lack of error message
« Reply #1 on: November 09, 2025, 01:54:36 pm »
This is likely due to the fact that after the first complete match, everything else is a comment.
Code: Pascal  [Select][+][-]
  1. {$if
  2.      (a <> 1)     // complete expression
  3.      (b <> 0) or  // comment
  4.      (c <> 3)     // comment
  5. }
This behavior is documented. Have to look it up, though. It has come up multiple times before.
Delphi 12.1 throws "E2066 Missing operator or semicolon"  so there is some ground to get this fixed.
« Last Edit: November 09, 2025, 02:07:47 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

n7800

  • Hero Member
  • *****
  • Posts: 583
  • Lazarus IDE contributor
    • GitLab profile
Re: Unexpected lack of error message
« Reply #2 on: November 09, 2025, 04:20:41 pm »
It seems the documentation doesn't mention anything about this. I couldn't find anything in the programmer's manual for the word "comment", so I created a request to add it to the documentation.

I only found a small mention on the wiki.

n7800

  • Hero Member
  • *****
  • Posts: 583
  • Lazarus IDE contributor
    • GitLab profile
Re: Unexpected lack of error message
« Reply #3 on: November 09, 2025, 04:30:34 pm »
Delphi 12.1 throws "E2066 Missing operator or semicolon"  so there is some ground to get this fixed.

I hope you'll create a issue for FPC?

Thaddy

  • Hero Member
  • *****
  • Posts: 18475
  • Here stood a man who saw the Elbe and jumped it.
Re: Unexpected lack of error message
« Reply #4 on: November 09, 2025, 05:20:23 pm »
It is only for {$ifdef} it seems, but the behavior is the same for {$if}:
https://www.freepascal.org/docs-html/current/prog/progsu31.html
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

n7800

  • Hero Member
  • *****
  • Posts: 583
  • Lazarus IDE contributor
    • GitLab profile
Re: Unexpected lack of error message
« Reply #5 on: November 09, 2025, 05:39:10 pm »
Thanks for finding this. In general, this seems to apply to all directives, I provided several examples in the issue.

 

TinyPortal © 2005-2018