Skip to content

Commit

Permalink
Fix extends of builtin type in getModelInstance (#10070)
Browse files Browse the repository at this point in the history
- Set the `isDerived` class to `true` when building instance trees for
  extends, otherwise extends of builtin types are incorrectly optimized
  away and cause issues later on.

Fixes #10069
  • Loading branch information
perost committed Jan 18, 2023
1 parent 7fce4bb commit a9f36c0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Script/NFApi.mo
Expand Up @@ -926,7 +926,7 @@ algorithm

case (_, ClassTree.INSTANTIATED_TREE(exts = ext_nodes))
algorithm
exts := list(buildInstanceTree(e) for e in ext_nodes);
exts := list(buildInstanceTree(e, isDerived = true) for e in ext_nodes);
components := list(buildInstanceTreeComponent(arrayGet(cls_tree.components, i))
for i in cls_tree.localComponents);
then
Expand Down
56 changes: 56 additions & 0 deletions testsuite/openmodelica/instance-API/GetModelInstanceExtends3.mos
@@ -0,0 +1,56 @@
// name: GetModelInstanceExtends3
// keywords:
// status: correct
// cflags: -d=newInst
//
//

loadString("
type MyReal
extends Real;
end MyReal;

model M
MyReal x;
end M;
");
getErrorString();

getModelInstance(M, prettyPrint=true);

// Result:
// true
// ""
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"x\",
// \"type\": {
// \"name\": \"MyReal\",
// \"restriction\": \"type\",
// \"extends\": [
// {
// \"baseClass\": \"Real\"
// }
// ],
// \"source\": {
// \"filename\": \"<interactive>\",
// \"lineStart\": 2,
// \"columnStart\": 3,
// \"lineEnd\": 4,
// \"columnEnd\": 13
// }
// }
// }
// ],
// \"source\": {
// \"filename\": \"<interactive>\",
// \"lineStart\": 6,
// \"columnStart\": 3,
// \"lineEnd\": 8,
// \"columnEnd\": 8
// }
// }"
// endResult
1 change: 1 addition & 0 deletions testsuite/openmodelica/instance-API/Makefile
Expand Up @@ -22,6 +22,7 @@ GetModelInstanceEvaluate1.mos \
GetModelInstanceExp1.mos \
GetModelInstanceExtends1.mos \
GetModelInstanceExtends2.mos \
GetModelInstanceExtends3.mos \
GetModelInstanceIcon1.mos \
GetModelInstanceIcon2.mos \
GetModelInstanceInnerOuter1.mos \
Expand Down

0 comments on commit a9f36c0

Please sign in to comment.