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

Commit 8481cc5

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Fix type in Ceval.evalArrayConstructor.
- Create a new type based on the actual sizes of the created arrays in evalArrayConstructor, instead of using the original type which might have non-constant dimensions. Belonging to [master]: - #2870
1 parent 3c1d34e commit 8481cc5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Compiler/NFFrontEnd/NFCeval.mo

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,7 @@ protected
27072707
algorithm
27082708
e := evalExpPartial(exp);
27092709
(e, ranges, iters) := createIterationRanges(e, iterators);
2710-
result := evalArrayConstructor2(e, ty, ranges, iters);
2710+
result := evalArrayConstructor2(e, ranges, iters);
27112711
end evalArrayConstructor;
27122712

27132713
function createIterationRanges
@@ -2731,33 +2731,38 @@ end createIterationRanges;
27312731

27322732
function evalArrayConstructor2
27332733
input Expression exp;
2734-
input Type ty;
27352734
input list<Expression> ranges;
27362735
input list<Mutable<Expression>> iterators;
27372736
output Expression result;
27382737
protected
2739-
Expression range;
2738+
Expression range, e;
27402739
list<Expression> ranges_rest, expl = {};
27412740
Mutable<Expression> iter;
27422741
list<Mutable<Expression>> iters_rest;
27432742
ExpressionIterator range_iter;
27442743
Expression value;
2745-
Type el_ty;
2744+
Type ty;
27462745
algorithm
27472746
if listEmpty(ranges) then
27482747
result := evalExp(exp);
27492748
else
27502749
range :: ranges_rest := ranges;
27512750
iter :: iters_rest := iterators;
27522751
range_iter := ExpressionIterator.fromExp(range);
2753-
el_ty := Type.unliftArray(ty);
27542752

27552753
while ExpressionIterator.hasNext(range_iter) loop
27562754
(range_iter, value) := ExpressionIterator.next(range_iter);
27572755
Mutable.update(iter, value);
2758-
expl := evalArrayConstructor2(exp, el_ty, ranges_rest, iters_rest) :: expl;
2756+
expl := evalArrayConstructor2(exp, ranges_rest, iters_rest) :: expl;
27592757
end while;
27602758

2759+
if listEmpty(expl) then
2760+
ty := Type.unliftArray(Expression.typeOf(exp));
2761+
else
2762+
ty := Expression.typeOf(listHead(expl));
2763+
end if;
2764+
2765+
ty := Type.liftArrayLeft(ty, Dimension.fromInteger(listLength(expl)));
27612766
result := Expression.makeArray(ty, listReverseInPlace(expl), literal = true);
27622767
end if;
27632768
end evalArrayConstructor2;

0 commit comments

Comments
 (0)