Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 4961b36

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Fix Call.reductionDefaultValue.
- Return no default value for reductions of arrays. The array type might contain unknown dimensions in functions, and the old frontend does the same thing. Belonging to [master]: - #2947
1 parent c4e03c8 commit 4961b36

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ uniontype Call
713713
Function.name(call.fn),
714714
Absyn.COMBINE(),
715715
Type.toDAE(call.ty),
716-
SOME(Expression.toDAEValue(reductionDefaultValue(call))),
716+
Expression.toDAEValueOpt(reductionDefaultValue(call)),
717717
fold_id,
718718
res_id,
719719
Expression.toDAEOpt(reductionFoldExpression(call.fn, call.ty, call.var, fold_id, res_id))),
@@ -730,19 +730,30 @@ uniontype Call
730730

731731
function reductionDefaultValue
732732
input Call call;
733-
output Expression defaultValue;
733+
output Option<Expression> defaultValue;
734734
protected
735735
Function fn;
736736
Type ty;
737737
algorithm
738738
TYPED_REDUCTION(fn = fn, ty = ty) := call;
739739

740-
defaultValue := match Absyn.pathFirstIdent(Function.name(fn))
741-
case "sum" then Expression.makeZero(ty);
742-
case "product" then Expression.makeOne(ty);
743-
case "min" then Expression.makeMaxValue(ty);
744-
case "max" then Expression.makeMinValue(ty);
745-
end match;
740+
if Type.isArray(ty) then
741+
defaultValue := NONE();
742+
else
743+
defaultValue := match Absyn.pathFirstIdent(Function.name(fn))
744+
case "sum" then SOME(Expression.makeZero(ty));
745+
case "product" then SOME(Expression.makeOne(ty));
746+
case "min" then SOME(Expression.makeMaxValue(ty));
747+
case "max" then SOME(Expression.makeMinValue(ty));
748+
else
749+
algorithm
750+
Error.addSourceMessage(Error.INTERNAL_ERROR,
751+
{getInstanceName() + " got unknown reduction name " + Absyn.pathFirstIdent(Function.name(fn))},
752+
sourceInfo());
753+
then
754+
fail();
755+
end match;
756+
end if;
746757
end reductionDefaultValue;
747758

748759
function reductionFoldExpression

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,11 @@ public
16811681
end match;
16821682
end toDAE;
16831683

1684+
function toDAEValueOpt
1685+
input Option<Expression> exp;
1686+
output Option<Values.Value> value = Util.applyOption(exp, toDAEValue);
1687+
end toDAEValueOpt;
1688+
16841689
function toDAEValue
16851690
input Expression exp;
16861691
output Values.Value value;

0 commit comments

Comments
 (0)