modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Creative Commons Attribution Share Alike 4.0 International
104 stars 40 forks source link

Clarify lookup rules of local renaming imports #504

Closed modelica-trac-importer closed 6 years ago

modelica-trac-importer commented 6 years ago

Reported by sjoelund.se on 9 Mar 2011 09:08 UTC The lookup rules in the specification as I read them causes some issues with Modelica.Media.Incompressible.TableBased (it should not flatten due to unbound constants after resolving import Poly = Modelica.Media.Incompressible.TableBased.Polynomials_Temp; see details below).

In this small example, D is a partial package because D.c is an unbound constant. We then extend the package and add a modifier to c. This is fine. The problem is that the package has an import g = D.f. This import is supposed to be resolved by lookup from the top level (13.2.11; but Dymola does this differently as import g = f is allowed).

Since it is resolved from the top level, c should no longer have a binding, making package C illegal. This means we either need to update the specification (for example by allowing local import g = f, which would not go through the top level scope) or update MSL to not use this feature.

partial package D
  import g = D.f;
  constant Real c;
  constant Real r = g();
  function f
    output Real r =  c;
  end f;
end D;

package C
  extends D(c = 0.5);
end C;

Migrated-From: https://trac.modelica.org/Modelica/ticket/504

modelica-trac-importer commented 6 years ago

Comment by HansOlsson on 23 Mar 2011 16:38 UTC The Polynomials_temp is different, since it does not use the unspecified constants - and no change is needed (but could be done for clarity).

In the package above it would be an error using C.r (since it is using D.f which relies on the unspecified constant D.c). Using C.f() is ok - assuming the extension of functions without algorithms.