Skip to content

Commit 54c8505

Browse files
authored
Handle checkModel on functions better (#10826)
Fixes #10821
1 parent 5e4205a commit 54c8505

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

OMCompiler/Compiler/NFFrontEnd/NFInst.mo

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ algorithm
152152
// Look up the class to instantiate.
153153
cls := lookupRootClass(classPath, top, context);
154154

155+
// If the class is a function (allowed with checkModel), do the usual function
156+
// handling to check that it's ok and return a dummy model since it won't be
157+
// used anyway.
158+
if SCodeUtil.isFunction(InstNode.definition(cls)) then
159+
(flatModel, functions, flatString) := instantiateRootFunction(cls, context);
160+
return;
161+
end if;
162+
155163
// Instantiate the class.
156164
inst_cls := instantiateRootClass(cls, context);
157165
execStat("NFInst.instantiate(" + name + ")");
@@ -335,6 +343,24 @@ algorithm
335343
insertGeneratedInners(clsNode, InstNode.topScope(clsNode), context);
336344
end instantiateRootClass;
337345

346+
function instantiateRootFunction
347+
input InstNode funcNode;
348+
input InstContext.Type context;
349+
output FlatModel flatModel;
350+
output FunctionTree functions;
351+
output String flatString = "";
352+
algorithm
353+
Function.instFunctionNode(funcNode, context, InstNode.info(funcNode));
354+
functions := FunctionTree.new();
355+
356+
for fn in Function.typeNodeCache(funcNode, context) loop
357+
functions := Flatten.flattenFunction(fn, functions);
358+
end for;
359+
360+
flatModel := FlatModel.FLAT_MODEL(InstNode.name(funcNode), {}, {}, {}, {}, {},
361+
ElementSource.createElementSource(InstNode.info(funcNode)));
362+
end instantiateRootFunction;
363+
338364
function instantiate
339365
input output InstNode node;
340366
input Modifier mod = Modifier.NOMOD();

0 commit comments

Comments
 (0)