Skip to content

Commit

Permalink
[NF] Fix type matching of boxed binary ops.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Apr 9, 2020
1 parent eee61a9 commit 98a8dbc
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
4 changes: 0 additions & 4 deletions .CI/compliance-newinst.failures
Expand Up @@ -105,11 +105,7 @@ ModelicaCompliance.Functions.Declarations.Illegal2
ModelicaCompliance.Functions.Derivative.PartialDerivative
ModelicaCompliance.Functions.ExternalObjects.ExternalObjectTable
ModelicaCompliance.Functions.ExternalObjects.ExternalObjectTableInFunction
ModelicaCompliance.Functions.HigherOrder.PartialApplication1
ModelicaCompliance.Functions.HigherOrder.PartialApplication2
ModelicaCompliance.Functions.HigherOrder.PartialApplication3
ModelicaCompliance.Functions.HigherOrder.Quadrature1
ModelicaCompliance.Functions.HigherOrder.Quadrature2
ModelicaCompliance.Functions.Restrictions.FunctionAssignInput
ModelicaCompliance.Inheritance.Flattening.DuplicateInheritedNeqClasses
ModelicaCompliance.Inheritance.Restrictions.ArrayClassWithComp
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -4789,7 +4789,7 @@ public
local
Type ty;

case Expression.BOX() then boxedExp.exp;
case BOX() then boxedExp.exp;

else
algorithm
Expand Down
25 changes: 24 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFTypeCheck.mo
Expand Up @@ -154,7 +154,9 @@ function checkBinaryOperation
algorithm
if Type.isComplex(Type.arrayElementType(type1)) or
Type.isComplex(Type.arrayElementType(type2)) then
(binaryExp,resultType) := checkOverloadedBinaryOperator(exp1, type1, var1, operator, exp2, type2, var2, info);
(binaryExp, resultType) := checkOverloadedBinaryOperator(exp1, type1, var1, operator, exp2, type2, var2, info);
elseif Type.isBoxed(type1) and Type.isBoxed(type2) then
(binaryExp, resultType) := checkBinaryOperationBoxed(exp1, type1, var1, operator, exp2, type2, var2, info);
else
(binaryExp, resultType) := match operator.op
case Op.ADD then checkBinaryOperationAdd(exp1, type1, exp2, type2, info);
Expand Down Expand Up @@ -288,6 +290,27 @@ algorithm
end if;
end matchOverloadedBinaryOperator;

public function checkBinaryOperationBoxed
input Expression exp1;
input Type type1;
input Variability var1;
input Operator op;
input Expression exp2;
input Type type2;
input Variability var2;
input SourceInfo info;
output Expression outExp;
output Type outType;
protected
Expression e1, e2;
Type ty1, ty2;
algorithm
(e1, ty1) := matchTypes(type1, Type.unbox(type1), exp1);
(e2, ty2) := matchTypes(type2, Type.unbox(type2), exp2);
(outExp, outType) := checkBinaryOperation(e1, ty1, var1, op, e2, ty2, var2, info);
end checkBinaryOperationBoxed;

protected
function checkOverloadedBinaryArrayAddSub
input Expression exp1;
input Type type1;
Expand Down
46 changes: 46 additions & 0 deletions testsuite/flattening/modelica/scodeinst/FunctionalArgBinary1.mo
@@ -0,0 +1,46 @@
// name: FunctionalArgBinary1
// keywords:
// status: correct
// cflags: -d=newInst
//

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

function f1
input F f;
input Real x;
output Real y;
algorithm
y := f(x) + f(x);
end f1;

function f2
input Real x;
output Real y = x * 2;
end f2;

model FunctionalArgBinary1
Real x = f1(f2, 1);
end FunctionalArgBinary1;

// Result:
// function f1
// input f<function>(#Real x) => #Real f;
// input Real x;
// output Real y;
// algorithm
// y := unbox(f(#(x))) + unbox(f(#(x)));
// end f1;
//
// function f2
// input Real x;
// output Real y = x * 2.0;
// end f2;
//
// class FunctionalArgBinary1
// Real x = f1(f2, 1.0);
// end FunctionalArgBinary1;
// endResult
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Expand Up @@ -514,6 +514,7 @@ FuncWildcard.mo \
FuncWrongType.mo \
FunctionalArg1.mo \
FunctionalArg2.mo \
FunctionalArgBinary1.mo \
FunctionalArgInvalidType1.mo \
FunctionDerivative1.mo \
FunctionDerivativeInvalidInput1.mo \
Expand Down

0 comments on commit 98a8dbc

Please sign in to comment.