Expected "XXX" to be a class, but found component instead.
I keep coming across an error of a form "Expected 'XXX' to be a class, but found component instead." when I try to insert a model into another model and I can't work out what is causing it. It seems to happen sporadically and I can't really work out what is causing it.
Most recently I was working on the attached "frame_model_pack" This contains "frame_model" which references two other models "keel" and "control_frame". This was working fine, then I made some minor adjustments to "control_frame" (changing the icon and tweaking some initial conditions) and now I get this error:
[1] 13:52:42 Translation Error
[frame_model_pack: 16:3-17:117]: Expected control_frame to be a class, but found component instead.
Unfortunately I saved the model and re-opened OMEdit so I can't simply undo back to the working state! I simply don't understand why it went from working to not working like this. If I reference "control_frame" in another model outside of "frame_model_pack" then it does still work. Also 'keel' is inside "frame_model_pack" and that has no problem being referenced by "frame_model", so it's not that you can't reference a model from within the same package (and as I say, this was working until I made some minor tweaks to control_frame).
From https://trac.openmodelica.org/OpenModelica/ticket/6000.
Have you cleared this issue?
@richman2024 no, thanks for reminding us.
Original ticket: https://trac.openmodelica.org/OpenModelica/ticket/6000
Steps to reproduce:
- load the following package in OMEdit
package P
model m
equation
end m;
model S
equation
end S;
end P;
- Open model
S - Drag and drop an instance of model
mintoS - OMEdit proposes to call it
m, click OK.
The following model is produced
model S
m m annotation(
Placement(visible = true, transformation(origin = {-20, -4}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
end S;
which is wrong because it uses the same name for the class and the component. When checking it, one gets:
Translation Error
P: 8:3-9:116: Expected m to be a class, but found component instead.
which is technically correct but completely obscure to a beginner that made the mistake to define a model starting with a small letter.
Expected Behaviour
OMEdit should not allow to get to this point in the first place.
@adeas31, I think the best option is that it refuses to accept an instance name equal to the class name, and issue a dialog suggesting to use names for the classes that start with a capital letter. In this way one also learns a basic convention of Modelica that may not be known to newbies.
OMedit could also propose a name with an added "1" to the class name in this case. However, this would encourage the newbie to continue with the bad habit of giving classes names that start with small letters. Hence, I'd prefer the other option.
@adeas31, please take care of this at your earliest convenience.
Thank you great support!
It doing work after I changed the class name start with a capital letter.
This is now fixed. OMedit proposes m1 as a name for the instance, and if I change it to m I get this error message