The proposed fix in the description is wrong: the compiler does not compare .pas and .dcu files folder by folder.

Measured with dcc32 of Delphi 13 and Delphi 7: Foo.dcu in one folder of the search path, Foo.pas with different content in another. In all cases the compiler compiled Foo.pas, whichever of the two folders came first, and whether the .pas file was newer, older or had exactly the timestamp of the source the .dcu was built from. It wrote the new Foo.dcu over the old one. Without Foo.pas in the search path, it used Foo.dcu.

So a .pas file anywhere in the compiler's folders (project folder, project search path, library path) wins over a .dcu file, and the thread already handles these folders correctly. The bug is only that the further folders from Ota.GetAllPossiblePaths (those of the project's units and of the file in the editor, the project group folder, the subfolders of the IDE's source folder, the search path favourites) are treated the same way as the compiler's folders.

Corrected fix: the thread gets the compiler's folders and the further folders separately and takes, in this order:

  1. the project's own units
  2. the first .pas file in the compiler's folders
  3. for a unit of which the compiler's folders only have a .dcu file: its source from the browsing path
  4. the first .pas file in the further folders, for units not found so far