Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

final or not final? #2676

Closed
d-hedberg opened this issue Oct 8, 2020 · 9 comments · Fixed by #2719
Closed

final or not final? #2676

d-hedberg opened this issue Oct 8, 2020 · 9 comments · Fixed by #2719
Labels
clarification Specification of feature is unclear, but not incorrect decided A decision has been made (label added before the spec is changed)

Comments

@d-hedberg
Copy link

In MyPackage.MyModel below, is the modification of a(x=4) legal (considering that the model A has a final prefix to it)?

package MyPackage
  model B
    parameter Real x;
  end B;

  final model A = B(x = 3); // Model A is made final here.

  model MyModel
    A a(x=4); // Legal?
  end MyModel;
end MyPackage;
@HansOlsson
Copy link
Collaborator

I would prefer it is legal, and think that it is easier to understand for replaceable.
The reason is that I would assume some people use 'final redeclare' to say that the class is choice, but still works as a normal class.

I would actually see three possibilities:

  1. It's only the choice of class A that is final; this prevents some modifications that are a bit odd.
  2. The entire class A is final, so even for 'final model A=B;' then MyModel would be illegal.
  3. Only the modified elements "inherit" final; the example suggests this.

I prefer 1, but https://specification.modelica.org/master/inheritance-modification-and-redeclaration.html#final-element-modification-prevention indicates 2.

@henrikt-ma
Copy link
Collaborator

Alternative 2 corresponds to my intuition about final, which I suppose I got from the cited 7.2.6 Final Element Modification Prevention one way or another.

@d-hedberg
Copy link
Author

I'd have to agree that alternative 2 is the only alternative that makes sense to me. I'd have a really hard time trying to convince Modelica users that if they declare a class final , parts of it can still be modified. That's confusing, and I'm pretty sure that the follow-up question would be: "How do I really make the class final then?".

@HansOlsson
Copy link
Collaborator

I'd have to agree that alternative 2 is the only alternative that makes sense to me. I'd have a really hard time trying to convince Modelica users that if they declare a class final , parts of it can still be modified. That's confusing, and I'm pretty sure that the follow-up question would be: "How do I really make the class final then?".

Agreed on second thought, and thus it seems this is just a question that has been answered and can be closed.
(If people just want to prohibit redeclare the solution is to use "redeclare" without final.)

@henrikt-ma
Copy link
Collaborator

Agreed on second thought, and thus it seems this is just a question that has been answered and can be closed.
(If people just want to prohibit redeclare the solution is to use "redeclare" without final.)

Perhaps we should still clarify that a final element doesn't have to be a component, and give an example of what it means for a type to be final?

@HansOlsson
Copy link
Collaborator

However, there are a number of modifiers for final classes (mostly/entirely final redeclare, of course) in MSL.

One example is in Modelica.Fluid.Examples.HeatExchanger.BaseClasses.BasicHX:

model BasicHX "Simple heat exchanger model"
 ...
Pipes.DynamicPipe pipe_1(
    redeclare final package Medium = Medium_1,
    ...
    redeclare final model HeatTransfer = HeatTransfer_1,
    ...
    redeclare final model FlowModel = FlowModel_1,

with Modelica.Fluid.Pipes.DynamicPipe:

model DynamicPipe "Dynamic pipe model with storage of mass and energy"
   ...
   HeatTransfer heatTransfer(
    redeclare final package Medium = Medium,
    final n=n,

(and similarly for the inherited FlowModel).

@d-hedberg
Copy link
Author

Are you saying that the final prefix for a class if occurring in a modification should be interpreted differently? That it should be allowed to change a parameter inside a redeclared final class? See example below.

package MyPackage
  model B
  end B;

  model C
    parameter Real x;
  end C;

  replaceable model A = B constrainedby B;
end MyPackage;

model MyModel
  package P = MyPackage(redeclare final model A = MyPackage.C(x=3)); // Model A is made final here.
  P.A a(x=4); // Legal?
end MyModel;

@HansOlsson
Copy link
Collaborator

Are you saying that the final prefix for a class if occurring in a modification should be interpreted differently?

No, it was just an observation that some had that idea - and we need to correct MSL to be consistent with this.
I'll make a PR.

HansOlsson added a commit to HansOlsson/Modelica that referenced this issue Oct 9, 2020
@HansOlsson HansOlsson added the clarification Specification of feature is unclear, but not incorrect label Oct 20, 2020
@HansOlsson
Copy link
Collaborator

Agreed on second thought, and thus it seems this is just a question that has been answered and can be closed.
(If people just want to prohibit redeclare the solution is to use "redeclare" without final.)

Perhaps we should still clarify that a final element doesn't have to be a component, and give an example of what it means for a type to be final?

Clarifying that and adding an example makes sense.

@HansOlsson HansOlsson added the decided A decision has been made (label added before the spec is changed) label Oct 20, 2020
HansOlsson added a commit to HansOlsson/ModelicaSpecification that referenced this issue Nov 17, 2020
HansOlsson added a commit that referenced this issue Nov 25, 2020
* Clarify final for classes.
Closes #2676
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
beutlich pushed a commit to HansOlsson/Modelica that referenced this issue Jan 14, 2021
beutlich pushed a commit to HansOlsson/Modelica that referenced this issue Feb 5, 2021
Otherwise the class will be final which in some cases could lead to problems.
modelica/ModelicaSpecification#2676
beutlich pushed a commit to beutlich/ModelicaStandardLibrary that referenced this issue Feb 15, 2021
Otherwise the class will be final which in some cases could lead to problems.
modelica/ModelicaSpecification#2676
beutlich pushed a commit to beutlich/ModelicaStandardLibrary that referenced this issue Feb 15, 2021
Otherwise the class will be final which in some cases could lead to problems.
modelica/ModelicaSpecification#2676
beutlich pushed a commit to beutlich/ModelicaStandardLibrary that referenced this issue Feb 26, 2021
Otherwise the class will be final which in some cases could lead to problems.
modelica/ModelicaSpecification#2676
beutlich pushed a commit to beutlich/ModelicaStandardLibrary that referenced this issue Feb 26, 2021
Otherwise the class will be final which in some cases could lead to problems.
modelica/ModelicaSpecification#2676
beutlich added a commit to modelica/ModelicaStandardLibrary that referenced this issue May 16, 2021
Otherwise the class will be final which in some cases could lead to problems.
modelica/ModelicaSpecification#2676

Co-authored-by: OLSSON Hans <Hans.Olsson@3ds.com>
beutlich added a commit to modelica/ModelicaStandardLibrary that referenced this issue May 16, 2021
Otherwise the class will be final which in some cases could lead to problems.
modelica/ModelicaSpecification#2676

Co-authored-by: OLSSON Hans <Hans.Olsson@3ds.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Specification of feature is unclear, but not incorrect decided A decision has been made (label added before the spec is changed)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants