#5172 closed defect (fixed)
[Replaceable] Binding equation in element redeclaration doesn't work
Reported by: | Owned by: | Per Östlund | |
---|---|---|---|
Priority: | normal | Milestone: | 1.19.0 |
Component: | New Instantiation | Version: | |
Keywords: | Binding redeclaration replaceable | Cc: | Peter Fritzson |
Description
Binding in Base2 should work according to specification, but it doesn't (as a result y2 = 10 in Base2)
package abc class Base1 replaceable Real y2 = 10; end Base1; class Base2 extends Base1; redeclare Integer y2= 5; end Base2; end abc;
Change History (8)
follow-up: 3 comment:1 by , 6 years ago
comment:2 by , 6 years ago
Component: | Backend → New Instantiation |
---|---|
Milestone: | 1.13.0 → 2.0.0 |
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 6 years ago
Replying to casella:
I see two problems with this example. The first is that I understand you should put the redeclare in the extends clause:
The redeclare in the description is a "redeclare as element", rather than a "redeclare as modifier". Both types of redeclare are valid, so that part is fine. The type is wrong though as you say, but we don't check that yet.
comment:4 by , 6 years ago
Yes, "redeclare as element" is used here.
Regarding redeclaration of Real to Integer - it shouldn't be correct (according to the spec, Real is not a subtype of Integer), but this example is taken from "Principles of Object-Oriented Modeling and Simulation with Modelica 3.3" (Peter Fritzson, second edition) - see p.157, section 4.3.1. And it works (both in OpenModelica and SystemModeler). So that's quite strange.
comment:5 by , 6 years ago
Cc: | added |
---|
Strange indeed. If I wrote a model with a replaceable Real variable y2, I should be auhorized to use der(y2)
in the model equation, since I expect y2
to be a subtype of Real, hence amenable to differentiation. In fact, adding a unit or a changing the max attribute doesn't create any problem from this point of view. But if I redeclare it as Integer, the model could be broken, as there's no such thing as the derivative of an Integer variable. Unless of course if the Integer is constant (then it could be interpreted as zero), but in general it could be broken.
Compilers should check these constraints statically to create a safe environment that avoids modellers getting into trouble with a-priori analysis. If they don't, they just leave the burden on the end user. It's not an ideal situation, but you can leave with it. Much worse is to have compilers that do not compile legal code, or compile it into wrong simulation code. I think we are currently mostly focusing on this kind of issues.
comment:6 by , 6 years ago
Milestone: | 2.0.0 → 2.1.0 |
---|
comment:7 by , 3 years ago
Milestone: | 2.1.0 → 1.18.0 |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
The new frontend is now the default and handles element redeclarations correctly. It still doesn't check constraining types, but that's covered by other tickets (like #1061) so I think we can close this one.
comment:8 by , 3 years ago
Milestone: | 1.18.0 → 1.19.0 |
---|
I see two problems with this example. The first is that I understand you should put the redeclare in the extends clause:
The current front-end gives the wrong result y2 = 10, but if you try the new front-end with the debug flag
-d=newInst
, you get the correct result. Please note that the new front-end will be the default from release 2.0.0 next year and we are no longer fixing remaining issues in the old front-end.The second problem is that, in fact, even the model shown above is illegal, because Integer is not a sub-type of Real, so the compiler should issue an error, or at least a warning. This one would instead be legal
and works nicely with the new front end (and in Dymola, for good measure).