ModelicaSpecification icon indicating copy to clipboard operation
ModelicaSpecification copied to clipboard

What do the expressions in choice mean?

Open maltelenz opened this issue 3 years ago • 5 comments

Consider these classes:

package C
  constant Real p = 1.0;

  model B
    parameter Real ch annotation(choices(choice = p));
  end B;

  model TestModel
    constant Real p = 2.0;
    B b;
  end TestModel;
end C;

Assume a user now opens C.TestModel, and applies the choice for b.ch using the tool of their choice.

What is the expected result? A:

model TestModel
  constant Real p = 2.0;
  B b(ch = p);
end TestModel;

Or B:

model TestModel
  constant Real p = 2.0;
  B b(ch = C.p);
end TestModel;

?

I find the specification unclear on this point.

maltelenz avatar Sep 22 '22 15:09 maltelenz

Wouldn't the case that "literal" repleacement is meant imply that one needs to apply global name lookup by giving full names starting with . when redeclaration choices are given as to be on the safe side for the case that an instantiation is taking place in an encapsulated class?

gwr-de avatar Sep 22 '22 16:09 gwr-de

The latter must be the desired solution, since it seems clear that the result should be the same regardless of where it is applied.

Dymola 2023 and 3D Experience R2022x (and earlier versions) handles this in some cases (the ones that have been most important I hope) - but not for all. Obviously the one constructing the model can avoid the ambiguity:

model B
    parameter Real ch annotation(choices(choice = .C.p));
  end B;

HansOlsson avatar Sep 29 '22 13:09 HansOlsson

Proposal: The choices should use lookup from where they occur to find classes and constants. It is possible to simplify that by start the names with a dot, see Section 5.3.3.

HansOlsson avatar Oct 11 '22 09:10 HansOlsson

Maybe it's worth illustrating the proposal with a situation where it is challenging (or even impossible) to express the modification that would correspond to a choice due to scoping rules at the place of the modification?

henrikt-ma avatar Oct 11 '22 09:10 henrikt-ma

Language group: Could mention inaccessible classes (due to protected), seen as bad modeling practice. Can illustrate working case with example as well.

HansOlsson avatar Oct 11 '22 14:10 HansOlsson