Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix purity handling in typing of fill #7498

Merged
merged 1 commit into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions OMCompiler/Compiler/NFFrontEnd/NFBuiltinCall.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1036,17 +1036,18 @@ protected
(arg, arg_ty, arg_var, arg_pur) := Typing.typeExp(arg, context, info);

if not (InstContext.inAlgorithm(context) or InstContext.inFunction(context)) then
if arg_var > Variability.PARAMETER or arg_pur == Purity.IMPURE or
Structural.isExpressionNotFixed(arg) then
if arg_var > Variability.PARAMETER then
Error.addSourceMessageAndFail(Error.NON_PARAMETER_EXPRESSION_DIMENSION,
{Expression.toString(arg), String(index),
List.toString(fillArg :: dimensionArgs, Expression.toString,
ComponentRef.toString(fnRef), "(", ", ", ")", true)}, info);
end if;

Structural.markExp(arg);
arg := Ceval.evalExp(arg);
arg_ty := Expression.typeOf(arg);
if arg_pur == Purity.PURE and not Structural.isExpressionNotFixed(arg) then
Structural.markExp(arg);
arg := Ceval.evalExp(arg);
arg_ty := Expression.typeOf(arg);
end if;
else
evaluated := false;
end if;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFPrefixes.mo
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ function purityMin
"Returns the least pure of the arguments."
input Purity p1;
input Purity p2;
output Purity p = if p1 > p2 then p2 else p1;
output Purity p = if p1 == Purity.IMPURE then p1 else p2;
end purityMin;

function directionFromSCode
Expand Down
37 changes: 37 additions & 0 deletions testsuite/flattening/modelica/scodeinst/FuncBuiltinFill3.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// name: FuncBuiltinFill3
// keywords: fill
// status: correct
// cflags: -d=newInst
//
// Tests the builtin fill operator.
//

model FuncBuiltinFill3
parameter Integer a[:, :] = {{1}, {2}, {3}};
Real x[3, 3];
equation
for i in 1:3 loop
x[:, 1:i] = zeros(3, a[i, 1]+0);
end for;
end FuncBuiltinFill3;

// Result:
// class FuncBuiltinFill3
// parameter Integer a[1,1] = 1;
// parameter Integer a[2,1] = 2;
// parameter Integer a[3,1] = 3;
// Real x[1,1];
// Real x[1,2];
// Real x[1,3];
// Real x[2,1];
// Real x[2,2];
// Real x[2,3];
// Real x[3,1];
// Real x[3,2];
// Real x[3,3];
// equation
// x[:,1:1] = fill(0.0, 3, a[1,1]);
// x[:,1:2] = fill(0.0, 3, a[2,1]);
// x[:,:] = fill(0.0, 3, a[3,1]);
// end FuncBuiltinFill3;
// endResult
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ FuncBuiltinDiv.mo \
FuncBuiltinEdge.mo \
FuncBuiltinFill.mo \
FuncBuiltinFill2.mo \
FuncBuiltinFill3.mo \
FuncBuiltinFloor.mo \
FuncBuiltinGetInstanceName.mo \
FuncBuiltinHomotopy.mo \
Expand Down