Incorrect "unit unused" hint when imports are used only for conditional compilation
Summary
The compiler incorrectly produces a "unit not used" hint if symbols from a unit are used only in conditional compilation checks ({$IF}
).
System Information
- Operating system: Fedora Linux 41 Beta
- Processor architecture: x86_64
- Compiler version: 3.2.2, 3.3.1 (c8286158)
Example Project
program unused;
uses
ctypes;
begin
{$IF SIZEOF(cint) >= 8)}
Writeln('cint is 8 bytes or larger')
{$ELSEIF SIZEOF(cint) >= 4)}
Writeln('cint is 4 bytes or larger')
{$ELSEIF SIZEOF(cint) >= 2)}
Writeln('cint is 2 bytes or larger')
{$ELSE}
Writeln('cint is a puny 1 byte')
{$ENDIF}
end.
What is the current bug behavior?
The compiler produces a hint suggesting that the ctypes
unit is unused:
unused.pas(4,2) Hint: Unit "ctypes" not used in unused
If one were to follow this hint and remove the import, the compilation fails:
unused.pas(7,6) Error: Identifier not found "CINT"
unused.pas(7,6) Error: Incompatible types: got "<erroneous type>" expected "Int64"
unused.pas(7,6) Error: Compile time expression: Wanted Boolean but got <erroneous type> at IF or ELSEIF
And so on for each of the checks.
What is the expected (correct) behavior?
The compiler should recognize that some symbols from the unit were used in the conditional compilation check, mark the unit as used, and not produce the hint.