View Issue Details

IDProjectCategoryView StatusLast Update
0037466LazarusIDEpublic2020-08-03 10:20
Reporternanobit Assigned ToMattias Gaertner  
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Platformwin32OSWindows 
Product Version2.1 (SVN) 
Summary0037466: IDE: wrong search-order for duplicate unit
DescriptionWrong search-order in a project which contains duplicate unitnames:
The IDE has a different search-order for unit than the compiler.

Compiler search-order is:
Projectfolder unit (eg. bugfixed unit) overrules units of other folders.

Example of project structure:
project\mainUnit.pas // contains "uses myUnit": IDE/FPC search in projectfolder
project\myUnit.pas // bugfixed version
project\shared\myOpenUnit.pas // contains "uses myUnit": FPC searches in projectfolder, IDE searches in sharedfolder
project\shared\myUnit.pas // original version

1) In IDE, open a unit (mainUnit or myOpenUnit) which contains the text "uses myUnit".
2) IDE command "Find declaration of myUnit" should open the used "myUnit".
3) Wrong behavior: IDE searches at first in the folder of the open unit.
Correct would be: IDE searches at first in the projectfolder.
TagsNo tags attached.
Fixed in Revision63675.
LazTarget-
WidgetsetWin32/Win64
Attached Files

Activities

nanobit

2020-08-02 19:30

reporter   ~0124512

Last edited: 2020-08-02 19:30

View 2 revisions

Thank you, but the command can still open the wrong myUnit.pas:
Consider the following project\shared\myOpenUnit.pas:

unit myOpenUnit;
interface
uses myUnit;
....

Now, right-click on "myUnit" for contextmenu,
then command "Find declaration of myUnit" opens this file:
project\shared\myUnit.pas // but it should open this:
project\myUnit.pas

Should, because the compiler uses only this unit:
project\myUnit.pas

Mattias Gaertner

2020-08-02 19:59

manager   ~0124515

Tricky.
If you would compile "fpc project\shared\myOpenUnit.pas" it would use project\shared\myUnit.pas.
Basically, which myUnit.pas is used depends on which unit is loaded first by fpc, the project\mainUnit.pas or project\shared\myOpenUnit.pas.
The IDE does not compile the project, it simply searches in the unit search path. This allows to ignore errors in other units and is much faster. Downside is that it works differently in some corner cases.
That's why the IDE warns about ambiguous files when you compile.

I don't see how to fix this easily.

nanobit

2020-08-03 09:36

reporter   ~0124523

Last edited: 2020-08-03 10:08

View 2 revisions

For the compiler, the locations of the referencing units are not relevant.
For example, if the whole project contains only a single reference to myUnit:
Only the file "project\shared\myOpenUnit.pas" contains the reference "uses myUnit;"
The compiler still uses "project\myUnit.pas" only, and never "project\shared\myUnit.pas"
The IDE cannot simply use the project search-paths (used by compiler)?

I mean this order: First use the project search-paths (like the compiler does),
and if the file is not found then use the folder of the referencing unit.

Mattias Gaertner

2020-08-03 10:17

manager   ~0124524

Last edited: 2020-08-03 10:20

View 2 revisions

No, fpc first searches in the already loaded units, then in the current directory of each unit and last in the unit path.
Delphi does the same.

Issue History

Date Modified Username Field Change
2020-08-02 12:27 nanobit New Issue
2020-08-02 16:26 Mattias Gaertner Assigned To => Mattias Gaertner
2020-08-02 16:26 Mattias Gaertner Status new => assigned
2020-08-02 18:27 Mattias Gaertner Status assigned => resolved
2020-08-02 18:27 Mattias Gaertner Resolution open => fixed
2020-08-02 18:27 Mattias Gaertner Fixed in Revision => 63675.
2020-08-02 18:27 Mattias Gaertner LazTarget => -
2020-08-02 18:27 Mattias Gaertner Widgetset Win32/Win64 => Win32/Win64
2020-08-02 19:30 nanobit Note Added: 0124512
2020-08-02 19:30 nanobit Note Edited: 0124512 View Revisions
2020-08-02 19:59 Mattias Gaertner Note Added: 0124515
2020-08-03 09:36 nanobit Status resolved => assigned
2020-08-03 09:36 nanobit Resolution fixed => open
2020-08-03 09:36 nanobit Note Added: 0124523
2020-08-03 10:08 nanobit Note Edited: 0124523 View Revisions
2020-08-03 10:17 Mattias Gaertner Note Added: 0124524
2020-08-03 10:20 Mattias Gaertner Note Edited: 0124524 View Revisions