Skip to content

Commit

Permalink
Allow partial calls in removed bindings (#7573)
Browse files Browse the repository at this point in the history
- Move the check for partial function calls from the instantiation to
  the typing, to allow such calls in bindings of removed conditional
  components.
  • Loading branch information
perost committed Jun 17, 2021
1 parent edac637 commit 9280895
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
14 changes: 14 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -172,6 +172,7 @@ public
if(BuiltinCall.needSpecialHandling(call)) then
(outExp, ty, var, pur) := BuiltinCall.typeSpecial(call, context, info);
else
checkNotPartial(cref, context, info);
ty_call := typeMatchNormalCall(call, context, info);
ty := typeOf(ty_call);
var := variability(ty_call);
Expand Down Expand Up @@ -199,6 +200,7 @@ public

case UNTYPED_REDUCTION()
algorithm
checkNotPartial(call.ref, context, info);
(ty_call, ty, var, pur) := typeReduction(call, context, info);
then
Expression.CALL(ty_call);
Expand Down Expand Up @@ -234,6 +236,18 @@ public
end match;
end typeCall;

function checkNotPartial
input ComponentRef fnRef;
input InstContext.Type context;
input SourceInfo info;
algorithm
if InstNode.isPartial(ComponentRef.node(fnRef)) and not InstContext.inRelaxed(context) then
Error.addSourceMessage(Error.PARTIAL_FUNCTION_CALL,
{ComponentRef.toString(fnRef)}, info);
fail();
end if;
end checkNotPartial;

function typeNormalCall
input output NFCall call;
input InstContext.Type context;
Expand Down
7 changes: 0 additions & 7 deletions OMCompiler/Compiler/NFFrontEnd/NFFunction.mo
Expand Up @@ -347,13 +347,6 @@ uniontype Function
algorithm
fn_ref := lookupFunction(functionName, scope, context, info);
(fn_ref, fn_node, specialBuiltin) := instFunctionRef(fn_ref, context, info);

if (InstNode.isClass(ComponentRef.node(fn_ref)) and InstNode.isPartial(fn_node)) and
not InstContext.inRelaxed(context) then
Error.addSourceMessage(Error.PARTIAL_FUNCTION_CALL,
{InstNode.name(fn_node)}, info);
fail();
end if;
end instFunction;

function instFunctionRef
Expand Down
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Expand Up @@ -778,6 +778,7 @@ PartialApplicationInvalidArg1.mo \
PartialApplicationInvalidArg2.mo \
PartialClass1.mo \
PartialFunction1.mo \
PartialFunction2.mo \
PartialLookup1.mo \
PartialLookup2.mo \
PartialType1.mo \
Expand Down
19 changes: 19 additions & 0 deletions testsuite/flattening/modelica/scodeinst/PartialFunction2.mo
@@ -0,0 +1,19 @@
// name: PartialFunction2
// keywords:
// status: correct
// cflags: -d=newInst
//

partial function f
input Real x;
output Real y;
end f;

class PartialFunction2
Real x = f(time) if false;
end PartialFunction2;

// Result:
// class PartialFunction2
// end PartialFunction2;
// endResult

0 comments on commit 9280895

Please sign in to comment.