Skip to content

Commit

Permalink
Use correct context in getModelInstance (#11279)
Browse files Browse the repository at this point in the history
Fixes #11278
  • Loading branch information
perost committed Sep 28, 2023
1 parent 6e31665 commit 653344b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
6 changes: 6 additions & 0 deletions OMCompiler/Compiler/Script/NFApi.mo
Expand Up @@ -867,6 +867,12 @@ algorithm
(_, top) := mkTop(SymbolTable.getAbsyn(), AbsynUtil.pathString(classPath));
mod := parseModifier(modifier, top);
cls_node := Inst.lookupRootClass(classPath, top, context);

if SCodeUtil.isFunction(InstNode.definition(cls_node)) then
context := InstContext.unset(context, NFInstContext.CLASS);
context := InstContext.set(context, NFInstContext.FUNCTION);
end if;

cls_node := Inst.instantiateRootClass(cls_node, context, mod);
execStat("Inst.instantiateRootClass");
inst_tree := buildInstanceTree(cls_node);
Expand Down
58 changes: 58 additions & 0 deletions testsuite/openmodelica/instance-API/GetModelInstanceFunction1.mos
@@ -0,0 +1,58 @@
// name: GetModelInstanceFunction1
// keywords:
// status: correct
// cflags: -d=newInst
//
//

loadString("
function f
input Integer N;
output Real y[N];
algorithm
y := fill(1.0, N);
end f;
");

getModelInstance(f, prettyPrint = true);

// Result:
// true
// "{
// \"name\": \"f\",
// \"restriction\": \"function\",
// \"elements\": [
// {
// \"$kind\": \"component\",
// \"name\": \"N\",
// \"type\": \"Integer\",
// \"prefixes\": {
// \"direction\": \"input\"
// }
// },
// {
// \"$kind\": \"component\",
// \"name\": \"y\",
// \"type\": \"Real\",
// \"dims\": {
// \"absyn\": [
// \"N\"
// ],
// \"typed\": [
// \"N\"
// ]
// },
// \"prefixes\": {
// \"direction\": \"output\"
// }
// }
// ],
// \"source\": {
// \"filename\": \"<interactive>\",
// \"lineStart\": 2,
// \"columnStart\": 3,
// \"lineEnd\": 7,
// \"columnEnd\": 8
// }
// }"
// endResult
1 change: 1 addition & 0 deletions testsuite/openmodelica/instance-API/Makefile
Expand Up @@ -43,6 +43,7 @@ GetModelInstanceExp2.mos \
GetModelInstanceExtends1.mos \
GetModelInstanceExtends2.mos \
GetModelInstanceExtends3.mos \
GetModelInstanceFunction1.mos \
GetModelInstanceIcon1.mos \
GetModelInstanceIcon2.mos \
GetModelInstanceIcon3.mos \
Expand Down

0 comments on commit 653344b

Please sign in to comment.