Opened 4 years ago
Closed 4 years ago
#5870 closed defect (fixed)
New FE does not resolve unqualified imported names
Reported by: | Andrea.Bartolini | Owned by: | perost |
---|---|---|---|
Priority: | high | Milestone: | 1.16.0 |
Component: | New Instantiation | Version: | v1.16.0-dev |
Keywords: | Cc: | casella |
Description
Please consider the test package below:
package Test import SIMSL = Modelica.SIunits; import Test.Types.*; package Types constant SIMSL.Pressure Pressure_nominal = 1e2; type Pressure = SIMSL.Pressure(nominal = Pressure_nominal); end Types; model M Pressure p = 1; end M; end Test;
If you open and check the model M the omc rises the following error:
[1] 13:17:15 Translation Error [Test: 3:3-3:22]: Import Test.Types not found in scope <top>. [2] 13:17:15 Translation Error Class Test.M not found in scope <top>.
As far as I understand, according to the Modelica specification 3.4 - Par. 5.3.1 - the import Test.Types.*; in the top-level package should be allowed.
Can you please give me a feedback...
Thanks in advance
OpenModelica 1.16.0~dev-208-gb567bd2
Sysop Linux Ubuntu 18.04
Change History (4)
comment:1 Changed 4 years ago by Andrea.Bartolini
- Summary changed from New FE des not resolve unqualified imported names to New FE does not resolve unqualified imported names
comment:2 Changed 4 years ago by casella
comment:3 Changed 4 years ago by perost
The issue with unqualified imports is that the names they import are not immediately evident from the declaration, so the NF must look up the imported package to see which names it contains. This is done while building the lookup tree for a class, so what happens is:
- Lookup is needed in Test, so Test is partially instantiated.
- Partial instantiation encounters an unqualified import for Test.Types.*.
- Partial instantiation tries to partially instantiate Test.Types to find out what elements it contains (partial instantiation is needed since the package may e.g. inherit other packages).
- Looking up Types in Test requires Test to be partially instantiated. But Test is already in the process of being partially instantiated due to step 1, so this fails.
It's probably possible to handle this corner case by delaying the lookup of the imported names until the lookup fails, in this case when Pressure needs to be looked up. That will complicate the lookup quite a bit and make it a bit slower though, but it should be doable.
But if it fails in Dymola too, is there a real need to handle this? Note that qualified imports does not have this issue since their name(s) can be deduced from the declaration, so looking up the element they import is instead done the first time that name is used.
comment:4 Changed 4 years ago by Andrea.Bartolini
- Resolution set to fixed
- Status changed from new to closed
Thanks Per,
is also my opinion that there isn't a real need to handle such a corner case.
Kind regards,
Andrea
The lookup also fails in Dymola, but we don't understand why