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 Andrea Bartolini, 5 years ago

Summary: New FE des not resolve unqualified imported namesNew FE does not resolve unqualified imported names

comment:2 by Francesco Casella, 5 years ago

The lookup also fails in Dymola, but we don't understand why

comment:3 by Per Östlund, 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:

  1. Lookup is needed in Test, so Test is partially instantiated.
  2. Partial instantiation encounters an unqualified import for Test.Types.*.
  3. 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).
  4. 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 by Andrea Bartolini, 5 years ago

Resolution: fixed
Status: newclosed

Thanks Per,
is also my opinion that there isn't a real need to handle such a corner case.

Kind regards,
Andrea

Note: See TracTickets for help on using tickets.