Forum > Packages and Libraries

PSA: Silent conflict between package name and unit name

(1/1)

gcscaglia:
This either a PSA or a bug report; I'm not sure which tbh.

Suppose you have the following file structure:


--- Code: ---Pkg/
  MyCode.lpk
  Units/
    MyCode.pas

--- End code ---

This will lead to confusing "Identifier not found" error messages. Worse still, the IDE will be able to find and even point you to those identifiers declarations, but the compiler will still complain they do not exists.

This behavior arises because, "under" the hood, an empty unit "Pkg/MyCode.pas" (note the path and extension) is created to pull in all units from the MyCode package. Since both "Pkg/MyCode.pas" and "Pkg/Units/MyCode.pas" have the same unit identifier and are compiled into the same output directory (under Pkg/lib/), the compiler picks up the empty unit (which is compiled last).

I do realize this is an unfortunate set of coincidences, but it surely made me waste a good hour figuring it out. Would it be possible to at least add an warning should this situation occur? Or, ideally, remove the need for the empty unit in the first place?

wp:

--- Quote from: gcscaglia on November 24, 2021, 05:52:27 pm ---This either a PSA or a bug report; I'm not sure which tbh.

--- End quote ---
PSA?


--- Quote from: gcscaglia on November 24, 2021, 05:52:27 pm ---it surely made me waste a good hour figuring it out.

--- End quote ---
This made you learn an elemental rule: never name a unit like a package, or to put it the other way round: never name a package such that a collision with a "normal" unit can occur. That's why packages often have something like "pkg" or "laz" in their name.

gcscaglia:

--- Quote from: wp on November 24, 2021, 06:04:12 pm ---PSA?

--- End quote ---

Public Service Announcement. It is just an cheeky way to say it is an advice to others.


--- Quote from: wp on November 24, 2021, 06:04:12 pm ---That's why packages often have something like "pkg" or "laz" in their name.

--- End quote ---

Well, while now my lesson is learned, I fear I will not be the last person to suffer from this. This is not intuitive at all (where does it says creating an package creates an unit with the same name?).

Anyway, the suggestion for improvement is made; at very least I hope this will save somebody the same hour I lost here.

*edit: fix typo

MarkMLl:

--- Quote from: gcscaglia on November 24, 2021, 06:20:47 pm ---
--- Quote from: wp on November 24, 2021, 06:04:12 pm ---PSA?

--- End quote ---

Public Service Announcement. It is just an cheeky way to say it is an advice to others.

--- End quote ---

I'm used to that from CIX in the UK. Once you have a community of people that spans 30+ years there's /conventions/.


--- Quote ---
--- Quote from: wp on November 24, 2021, 06:04:12 pm ---That's why packages often have something like "pkg" or "laz" in their name.

--- End quote ---

Well, while now my lesson is learned, I fear I will not be the last person to suffer from this. This is not intuitive at all (where does it says creating an package creates an unit with the same name?).

Anyway, the suggestion for improvement is made; at very least I hope this will save somebody the same hour I lost here.

--- End quote ---

I'm inclined to agree with you FWIW. If this /can/ be checked it /should/ be checked: if I wanted my software's robustness to be dependant on adherence to conventions I'd use C.

MarkMLl

Navigation

[0] Message Index

Go to full version