From a9f36c021fdb70ed479f8a352ec85057dfd0c53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Wed, 18 Jan 2023 17:27:52 +0100 Subject: [PATCH] Fix extends of builtin type in getModelInstance (#10070) - 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 --- OMCompiler/Compiler/Script/NFApi.mo | 2 +- .../instance-API/GetModelInstanceExtends3.mos | 56 +++++++++++++++++++ testsuite/openmodelica/instance-API/Makefile | 1 + 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 testsuite/openmodelica/instance-API/GetModelInstanceExtends3.mos diff --git a/OMCompiler/Compiler/Script/NFApi.mo b/OMCompiler/Compiler/Script/NFApi.mo index 14b857c3638..d12862ed059 100644 --- a/OMCompiler/Compiler/Script/NFApi.mo +++ b/OMCompiler/Compiler/Script/NFApi.mo @@ -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 diff --git a/testsuite/openmodelica/instance-API/GetModelInstanceExtends3.mos b/testsuite/openmodelica/instance-API/GetModelInstanceExtends3.mos new file mode 100644 index 00000000000..1e4b7c06fb2 --- /dev/null +++ b/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\": \"\", +// \"lineStart\": 2, +// \"columnStart\": 3, +// \"lineEnd\": 4, +// \"columnEnd\": 13 +// } +// } +// } +// ], +// \"source\": { +// \"filename\": \"\", +// \"lineStart\": 6, +// \"columnStart\": 3, +// \"lineEnd\": 8, +// \"columnEnd\": 8 +// } +// }" +// endResult diff --git a/testsuite/openmodelica/instance-API/Makefile b/testsuite/openmodelica/instance-API/Makefile index b4563b7a513..cee2136d01c 100644 --- a/testsuite/openmodelica/instance-API/Makefile +++ b/testsuite/openmodelica/instance-API/Makefile @@ -22,6 +22,7 @@ GetModelInstanceEvaluate1.mos \ GetModelInstanceExp1.mos \ GetModelInstanceExtends1.mos \ GetModelInstanceExtends2.mos \ +GetModelInstanceExtends3.mos \ GetModelInstanceIcon1.mos \ GetModelInstanceIcon2.mos \ GetModelInstanceInnerOuter1.mos \