#5356 closed defect (fixed)
Replaceable error with new FrontEnd
Reported by: | Niklas Worschech | Owned by: | Per Östlund |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | New Instantiation | Version: | |
Keywords: | replaceable, new FrontEnd | Cc: | Florian.Werner@… |
Description
For the following model
package FrontEnd model Test Model1 model1_1(redeclare model icon = Icon2) annotation (Placement(transformation(extent={{-24,-2},{-4,18}}))); annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(coordinateSystem( preserveAspectRatio=false))); end Test; model Model1 replaceable model icon = FrontEnd.Icon1 constrainedby FrontEnd.BaseIcon annotation(choicesAllMatching = true); extends icon; annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(coordinateSystem( preserveAspectRatio=false))); end Model1; model Icon1 extends FrontEnd.BaseIcon; annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={Text( extent={{0,-100},{0,100}}, lineColor={0,128,255}, fillColor={255,255,255}, fillPattern=FillPattern.None, textString="1")}), Diagram(coordinateSystem( preserveAspectRatio=false))); end Icon1; model Icon2 extends FrontEnd.BaseIcon; annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={Text( extent={{0,-100},{0,100}}, lineColor={0,128,255}, fillColor={255,255,255}, fillPattern=FillPattern.None, textString="2")}), Diagram(coordinateSystem( preserveAspectRatio=false))); end Icon2; model BaseIcon annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={Ellipse( extent={{-100,100},{100,-100}}, fillColor={255,255,255}, fillPattern=FillPattern.Solid, lineColor={0,0,0})}), Diagram(coordinateSystem(preserveAspectRatio=false))); end BaseIcon; end FrontEnd;
the new FrontEnd reports the error:
'Error: Class icon in extends icon is replaceable.'
If this is a error in the model, but with the old FrontEnd it works or is this a problem with the new FrontEnd?
Change History (8)
comment:1 by , 6 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
follow-up: 3 comment:2 by , 6 years ago
Maybe the error message can be changed from:
'Error: Class icon in extends icon is replaceable.'
into:
'Error: Class icon in extends icon is replaceable; base classes are not allowed to be replaceable.'
comment:3 by , 6 years ago
Replying to anonymous:
'Error: Class icon in extends icon is replaceable; base classes are not allowed to be replaceable.'
@perost, I think this is a very good idea, we already had other users getting into the same dead end.
I would suggest the following message:
Error: Class icon in extends icon is replaceable. Base classes ar not allowed to be replaceable in Modelica 3.x, see Modelica specification 7.1.4.
comment:4 by , 6 years ago
The formulation from @casella is no doubt the clearest, assuming that the numbering of MS clauses does not change over the versions.
I suppose this is a general question: if we trust MS clause numbering is stable, we can add useful details to error messages
follow-up: 6 comment:5 by , 6 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Reopening this so it's not forgotten.
It's actually not just the base class that's not allowed to be replaceable, but the name used in the extends clause must be transitively non-replaceable. I.e. every part of the class name much be non-replaceable, which is why the error message currently says "class ... in extends ...".
I agree that the current error could be clearer, but I don't think referencing the specification is a good idea since we don't do it anywhere else. If a user is interested enough to read the specification it's not hard to find the relevant section.
follow-up: 8 comment:6 by , 6 years ago
Replying to perost:
Reopening this so it's not forgotten.
Thanks
I agree that the current error could be clearer, but I don't think referencing the specification is a good idea since we don't do it anywhere else. If a user is interested enough to read the specification it's not hard to find the relevant section.
Honestly, sometimes the relevant section is not so easy to find. For example, understanding why I can access a function in an outer model, but not a model or a package, always takes me some time and effort.
Anyway, I agree that either we always refer to the spec, or we never do it, so I would write:
Error: Class icon in extends icon is replaceable. Base classes ar not allowed to be replaceable in Modelica 3.x.
I'd keep the reference to Modelica 3.x, because maybe one is trying to adapt an old model.
Regarding transitively non-replaceable classes, I'm not sure how to make this clear in an error message. However, I would be strongly in favour of mentioning that replaceable base classes are forbidden, even if that is not the most general possible case. Some partial info is better than no info at all.
comment:7 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
I just checked PR #2944, sounds good.
comment:8 by , 6 years ago
Replying to casella:
Replying to perost:
Reopening this so it's not forgotten.
Thanks
I agree that the current error could be clearer, but I don't think referencing the specification is a good idea since we don't do it anywhere else. If a user is interested enough to read the specification it's not hard to find the relevant section.
Honestly, sometimes the relevant section is not so easy to find. For example, understanding why I can access a function in an outer model, but not a model or a package, always takes me some time and effort.
Anyway, I agree that either we always refer to the spec, or we never do it, so I would write:
Error: Class icon in extends icon is replaceable. Base classes ar not allowed to be replaceable in Modelica 3.x.
I'd keep the reference to Modelica 3.x, because maybe one is trying to adapt an old model.
Regarding transitively non-replaceable classes, I'm not sure how to make this clear in an error message. However, I would be strongly in favour of mentioning that replaceable base classes are forbidden, even if that is not the most general possible case. Some partial info is better than no info at all.
As you've already seen I changed the error message in 1784812, and it's now:
Error: Class 'icon' in 'extends icon' is replaceable, the base class name must be transitively non-replaceable.
I.e. I added some quotation marks to avoid class names blending into the error message, and added the bit about transitively non-replaceable.
What transitively non-replaceable means might not be obvious to a user, but it has it's own section in the specification (6.2.1) that's simply called "Transitively non-Replaceable". It's also a term that's fairly easy to search for, since it's unique to Modelica.
Mentioning Modelica 3.x might be a good idea, but that's really the only version that the new frontend supports anyway. The new frontend relies on the fact that base classes are not allowed to be replaceable to optimize the handling of extends, so it's not an error message that can be turned off by using e.g. --std=2.x
.
A base class is not allowed to be replaceable, see 7.1.4 in the Modelica specification. This works in the old frontend simply because it doesn't check this, but the new frontend follows the specification more strictly in this case.