@@ -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);
336344end 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+
338364function instantiate
339365 input output InstNode node;
340366 input Modifier mod = Modifier . NOMOD ();
0 commit comments