Recent

Author Topic: The compiler fails to warn on syntax errors  (Read 909 times)

AlexanderK

  • New Member
  • *
  • Posts: 17
The compiler fails to warn on syntax errors
« on: January 14, 2026, 02:59:21 pm »
I've noticed that the compiler fails to warn on syntax errors in existing units. In newly created units it does warn. For Example,
Code: Pascal  [Select][+][-]
  1. unit ConstrainedTypes;
  2. {$mode Delphi}
  3. interface
  4. THIS_SHOULD_FAIL; // Compiles successfully despite being missing in implementation
  5. uses
  6.   Classes, SysUtils;
  7. implementation
  8. end.

The filepath of unit ConstrainedTypes refers to the project folder. I deleted all .ppu, .o and .compiled files and I did Clean and Rebuild. It didn't help.

In a newly created unit the compiler fails as expected.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode Delphi}
  3. interface
  4. THIS_SHOULD_FAIL; // Fails as expected: unit1.pas(7,1) Error: Syntax error, "IMPLEMENTATION" expected but "identifier THIS_SHOULD_FAIL"
  5. uses
  6.   Classes, SysUtils;
  7. implementation
  8. end.  

Any thoughts?

Lazarus 4.4 /FPC 3.2.2
x86_64-win64

 
« Last Edit: January 14, 2026, 03:16:20 pm by AlexanderK »

Nicole

  • Hero Member
  • *****
  • Posts: 1303
Re: The compiler fails to warn on syntax errors
« Reply #1 on: January 14, 2026, 03:23:25 pm »
Thank you for this posting. I had the feeling as well, but never was able to focus it as you did.

Sometimes I make an edit, an error occurs, I search it, and then I find a strange thing.
I wonder: How could this run all the time with this?

I delete the mentioned files regularly.
As I was that clueless about, I preferred to ignore it.


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12109
  • Debugger - SynEdit - and more
    • wiki
Re: The compiler fails to warn on syntax errors
« Reply #2 on: January 14, 2026, 03:53:06 pm »
Compile with -va and the check the output.

If you compile in the IDE you need to "Copy all and original messages" and paste them into an editor of your choice. Otherwise you will not see all the messages.

There will be for each file a number of messages, where it tried to find the file, where it found the file, and where it tried and maybe found ppu files.

If you file is being compiled it must be in the list, with at least one try for ppu, and a try and found for pas (or pp).

AlexanderK

  • New Member
  • *
  • Posts: 17
Re: The compiler fails to warn on syntax errors
« Reply #3 on: January 15, 2026, 12:17:05 pm »
That helped to identify the issue, though attempts to fix in the traditional ways didn't help. Even creating a brand-new project, and copying the source .pas files (and only the .pas files) to it resulted in the same problem - "Compiles successfully despite being missing in implementation". Ultimately, I created a new project, created new units (File->New Unit), named them the same as the source units, opened the source units in Notedpad and just copied their contents into the newly created ones, and that solved the issue. I have no clue what happened here. Copying the project folder multiple times between machines—as-is and without a 'Publish Project'—is the only thing I can think of that could have caused this. Thank you for the reply.

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 386
  • I use FPC [main] 💪🐯💪
Re: The compiler fails to warn on syntax errors
« Reply #4 on: January 15, 2026, 12:32:12 pm »
Is this "THIS_SHOULD_FAIL" real name, or did you change it to something else for the forum? In other words, the behavior is the same as described on the forum
I may seem rude - please don't take it personally

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12109
  • Debugger - SynEdit - and more
    • wiki
Re: The compiler fails to warn on syntax errors
« Reply #5 on: January 15, 2026, 12:44:31 pm »
That helped to identify the issue, though attempts to fix in the traditional ways didn't help.

And what was the issue?
Was there a ppu file that maybe wasn't expected, but used instead of compiling?

Just one thing that comes to mind, when talking about unexpected ppu files. Custom settings in the path config (package(s) and/or project). If by any chance any file is accessible through more than one path.... (e.g. package and project). That is a sure way to get odd behaviour.

AlexanderK

  • New Member
  • *
  • Posts: 17
Re: The compiler fails to warn on syntax errors
« Reply #6 on: January 15, 2026, 10:32:57 pm »
Quote
Is this "THIS_SHOULD_FAIL" real name
It is not, it was inserted on purpose in my code to stress that if something changes in interface without a corresponding change in implementation, the code still compiles successfully.

AlexanderK

  • New Member
  • *
  • Posts: 17
Re: The compiler fails to warn on syntax errors
« Reply #7 on: January 15, 2026, 10:51:59 pm »
Quote
And what was the issue?
Was there a ppu file that maybe wasn't expected, but used instead of compiling?

There were no .ppu files with the same filename in the -va report, whatsoever. The compiler just ignores that .pas file for no reason.

Moreover, when I created a brand-new project and copied the source .pas file to its folder and added it to Project Inspector, the result was the same. The -va report shows no sign of the unit. The compiler doesn't see it.

Anyway, I resolved it by creating a new unit with the same name (File->New Unit) and copy-pasting the source code into it.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12109
  • Debugger - SynEdit - and more
    • wiki
Re: The compiler fails to warn on syntax errors
« Reply #8 on: January 15, 2026, 11:18:28 pm »
I don't know exactly all the rules between ppu and pas.

Afaik, if both are in path (during the same call to FPC / i.e. not different compiles, like 2 separate packages), then the date is compared.... afaik.

But, one thing for sure (99.99%): if the ppu was build with -Ur then it will be forever. The compiler will take that ppu if it sees it, and never rebuild it.

If you still have it: ppudump might tell.

dseligo

  • Hero Member
  • *****
  • Posts: 1653
Re: The compiler fails to warn on syntax errors
« Reply #9 on: January 16, 2026, 01:41:21 am »
I've noticed that the compiler fails to warn on syntax errors in existing units. In newly created units it does warn. For Example,

What if you create some new procedure in this existing unit? Can you call it from main program or do you get an error?

Something like this:
Code: Pascal  [Select][+][-]
  1. unit ConstrainedTypes;
  2. {$mode Delphi}
  3. interface
  4.  
  5. procedure MyTestProcedure;
  6.  
  7. uses
  8.   Classes, SysUtils;
  9. implementation
  10.  
  11. procedure MyTestProcedure;
  12. begin
  13.   WriteLn('In unit.');
  14. end;
  15.  
  16. end.

What if you rename this unit and try to compile program?
Do you have this unit in Project Inspector?

AlexanderK

  • New Member
  • *
  • Posts: 17
Re: The compiler fails to warn on syntax errors
« Reply #10 on: January 17, 2026, 04:35:04 pm »
Finally, the real cause was found.
The dependency chain was .lpr -> Unit A -> Unit B -> ConstrainedTypes. Accidently, the reference to Unit A was removed from .lpr. This broke the dependency tree, so the compiler treated the unit as "dead code" and ignored it entirely—including the syntax errors.

My bad.
Thank you all for helping me sort this out.

 

TinyPortal © 2005-2018