Delphi-RAG-Lint
Delphi tooling · Safe fixes

Proof That the Compiler Saw the Fix

When drag-lint fixes your code it builds the project before and after the write, and rolls the fix back if the second build fails. That check had a blind spot: a build can succeed without ever compiling the file that was changed. Since 1.66 the second build has to prove that it compiled every rewritten unit. If it cannot, the fix is refused and the file stays byte for byte as it was.

Availability

The compile gate has guarded lint --fix --apply by default since 1.51, whenever --project names a .dproj. The build proof is new in drag-lint 1.66.0-alpha, released 2026-12-05, and covers every verb that writes through the gate except cycles --fix. Every output below is real output of 1.66.0-alpha and, in section 04, of 1.65.0-alpha, on the small project in section 01 (paths shortened to ...; progress lines and general notes left out).

We fix lint findings by the hundred on Micronite, the quality and production-control software we build for manufacturers, so a fix that only looks safe is not good enough for us. A fix is a text edit. Whether the edited unit still compiles is not something a linter should guess, so drag-lint asks the Delphi compiler: build 1 before the write, build 2 after it, roll back on any error. But "build 2 had no errors" only means something if build 2 compiled the file. A unit that sits in the folder but was dropped from the project, a second working copy of the same unit, a same-named unit that the search path finds first: in all three the project builds clean whatever the edit did, because the compiler never opens the edited file.

01 — The fixture

A project, and a unit it no longer compiles

The folder shop holds Shop.dproj and Shop.dpr, which uses one unit, Orders.pas. A second unit, Archive.pas, still sits in the folder but is no longer in the project. Both units have the same small finding on line 22: an as TObject cast on a variable that is already an object.

program Shop;
{$APPTYPE CONSOLE}
uses
  Orders in 'Orders.pas';
begin
  RunAll;
end.

Orders.pas, line 22 inside the try; Archive.pas has the same routine shape with LItem: TArchiveItem:

procedure Log(const pObj: TObject);
begin
  if pObj = nil then Exit;
end;

procedure LogOrder;
begin
  var LOrder: TOrder := TOrder.Create;
  try
    Log(LOrder as TObject);
  finally
    LOrder.Free;
  end;
end;
02 — Index and lint

Two findings, one in each unit

Step 1. Index the folder into a database of its own. --library-db none keeps this small example independent of the Delphi library index.

drag-lint index . --db shop.sqlite --library-db none

Done. Files: 3, Symbols: 14, Refs: 28, 0.20s, parse-errors=0

Step 2. Lint the whole index.

drag-lint lint-all --db shop.sqlite

...\shop\Archive.pas:22:9  [info] redundant-as-tobject: Redundant 'as TObject' cast - every Delphi object is already a TObject
...\shop\Orders.pas:22:9  [info] redundant-as-tobject: Redundant 'as TObject' cast - every Delphi object is already a TObject
...\shop\Archive.pas:9:1  [info] unused-public-symbol: Exported routine ArchiveOne has no references in the index -- possible dead public API
lint-all: 3 finding(s) -- 0 error(s), 0 warning(s), 3 info, 0 hint -- 3 file(s) scanned -- report: ...\shop\lint-report-20261205.txt

The third finding already hints at the problem: nothing in the index uses ArchiveOne.

03 — A unit the project compiles

The fix is written, and proved

Step 3. A dry run shows the edit without writing it.

drag-lint lint --in Orders.pas --db shop.sqlite --fix

File: Orders.pas
  replace L22:C9..26 -> "LOrder"
autofix: 1 fixable finding(s) -- pass --apply to write

Step 4. Apply it through the compile gate of Shop.dproj.

drag-lint lint --in Orders.pas --db shop.sqlite --fix --apply --project Shop.dproj

drag-lint: note: --fix --apply writes through the compile gate of Shop.dproj (--no-compile-gate writes unbuilt)
lint --fix: baseline build -- started
lint --fix: build after the edit -- started
compile gate: build 1 (before the write): 0 error(s), 0 warning(s), 0 hint(s)
compile gate: build 2 (after the write): 0 error(s), 0 warning(s), 0 hint(s)
compile gate: no new warnings or hints after the write
compile gate: proof: build 2 compiled every rewritten source file (1)
autofix: applied 1 edit(s) across 1 file(s) (.BCK backup written)

Exit code 0. Line 22 now reads Log(LOrder);, the old text is in Orders.pas.BCK1, and the proof: line is new in 1.66: one rewritten file, and build 2 compiled it.

04 — The blind spot, in 1.65

Two clean builds that never opened the file

Step 5. On a second, untouched copy of the folder, indexed by 1.65.0-alpha the same way, fix Archive.pas through the same project.

drag-lint lint --in Archive.pas --db shop.sqlite --fix --apply --project Shop.dproj

drag-lint: note: --fix --apply writes through the compile gate of Shop.dproj (--no-compile-gate writes unbuilt)
lint --fix: baseline build -- started
lint --fix: build after the edit -- started
compile gate: build 1 (before the write): 0 error(s), 0 warning(s), 0 hint(s)
compile gate: build 2 (after the write): 0 error(s), 0 warning(s), 0 hint(s)
compile gate: no new warnings or hints after the write
autofix: applied 1 edit(s) across 1 file(s) (.BCK backup written)

Exit code 0, and Archive.pas line 22 now reads Log(LItem);. The build output folder shows why both builds were clean:

Win64\Debug\Orders.dcu
Win64\Debug\Shop.exe

There is no Archive.dcu. The compiler never opened Archive.pas, before the edit or after it. This edit happens to be correct, but the gate would have printed the same two clean lines for an edit that does not compile at all: it reported a check that never looked at the file.

05 — The same fix in 1.66

REFUSED (not-compiled), nothing written

Step 6. Back in the first copy, reindex (step 4 changed Orders.pas, and the lint reads the index), then try the same fix with 1.66.

drag-lint index . --db shop.sqlite --library-db none

Done. Files: 3, Symbols: 14, Refs: 27, skipped 2 up-to-date, 0.39s, parse-errors=0

drag-lint lint --in Archive.pas --db shop.sqlite --fix --apply --project Shop.dproj

drag-lint: note: --fix --apply writes through the compile gate of Shop.dproj (--no-compile-gate writes unbuilt)
lint --fix: baseline build -- started
lint --fix: build after the edit -- started
compile gate: build 1 (before the write): 0 error(s), 0 warning(s), 0 hint(s)
compile gate: build 2 (after the write): 0 error(s), 0 warning(s), 0 hint(s)
REFUSED (not-compiled): lint --fix: Shop.dproj builds after the rewrite, but its build did not compile ...\shop\Archive.pas, so it proves nothing for the rewrite (a unit outside the project, or a same-named unit found first on its search path); rolled back, project not changed

Exit code 1. Both builds are still clean; what changed is that drag-lint no longer takes a clean build as proof. The SHA-1 of Archive.pas before and after the run:

14895B1B0956B0C74D6CC59E5960E96B23AA761B
14895B1B0956B0C74D6CC59E5960E96B23AA761B

To get the fix written, point --project at a project that does compile the unit, or add the unit to this one. If nothing uses the unit, as the unused-public-symbol finding of step 2 suggests, the better fix may be to delete it. --no-compile-gate still writes without building, when you choose to.

06 — How the proof works

One compiler hint per rewritten file

  • Before build 2, each rewritten .pas, .dpr or .dpk gets one line at its very top: a {$MESSAGE HINT 'dlgp-...'} directive. No other file is touched.
  • Build 2 runs msbuild /t:Build /p:DCC_Hints=true, so the hint shows up even in a project that switches hints off.
  • drag-lint reads the build log. Every rewritten file's hint present: the proof: line. Any one missing: REFUSED (not-compiled), the files named, every file rolled back, exit code 1.
  • The lines come out again before the run ends. They are never counted in the build 2 line or reported as new hints: in step 4 the build 2 line reads 0 hint(s), and after the runs above no file in the folder holds a dlgp- line.

The same proof backs rename --apply, the naming fixes of lint --fix, the multi-project rename and the other gated refactorings. In the language server, textDocument/rename can now go through the gate too: set renameCompileGate: true in the client settings (off by default) and the rename is built on a scratch copy of the project first; a refusal comes back as error -32803 naming the kind, for example not-compiled or compile-error.

07 — Why it is repeatable

A deterministic Delphi algorithm, not AI and not manual work

The finding and the edit come from the index drag-lint builds by parsing your source. The verdict comes from the Delphi compiler, and the proof is a plain fact read from its log: the hint of each rewritten file is there or it is not. No model judges whether a fix looks right, and nobody has to open the build output and check which units were compiled, as we did by hand in step 5. The same source and project give the same answer on every run and on every machine.

08 — Limits

What to know before you rely on it

  • It proves the unit compiled, not that it behaves the same. The gate catches a fix that breaks the build or that the build never saw; your tests still judge behaviour.
  • .dfm, .inc and other non-source files carry no proof line (an .inc's includer may switch hints off).
  • cycles --fix does not write through the gate.
  • Without --project, or with --no-compile-gate, nothing is built and nothing is proved, as before.
  • The gate needs RAD Studio on the machine (rsvars.bat; --rsvars and --build-timeout adjust it) and builds the project twice. On this three-file fixture the eight commands of this article (both engines, six builds among them) took 31 seconds together.
  • Every gate build forces DCC_Hints=true, so a project that hides hints now sees them counted in builds 1 and 2 alike.
  • Behaviour change for scripts: a fix that 1.65 applied with exit code 0 can now end REFUSED (not-compiled) with exit code 1.

Output measured 2026-12-05 with drag-lint 1.66.0-alpha and, for section 04, 1.65.0-alpha, on a three-file fixture; each run was checked by its exit code, the files' SHA-1 and the build output folder. The 1.65 run used a bare copy of the 1.65 release engine and printed a note that it found no manifest, left out above. Section 06 comes from the feature's help page and the 1.66 release notes; the proof line itself is in the file only while build 2 runs and was not captured.