Opened 5 years ago
Closed 5 years ago
#5870 closed defect (fixed)
New FE does not resolve unqualified imported names
Reported by: | Andrea Bartolini | Owned by: | Per Östlund |
---|---|---|---|
Priority: | high | Milestone: | 1.16.0 |
Component: | New Instantiation | Version: | v1.16.0-dev |
Keywords: | Cc: | Francesco 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 by , 5 years ago
Summary: | New FE des not resolve unqualified imported names → New FE does not resolve unqualified imported names |
---|
comment:2 by , 5 years ago
comment:3 by , 5 years ago
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
, soTest
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
inTest
requiresTest
to be partially instantiated. ButTest
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 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | new → 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