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

Commit 3be99fe

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Handle empty arrays better.
Belonging to [master]: - #2183 - OpenModelica/OpenModelica-testsuite#849
1 parent 5614078 commit 3be99fe

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,8 +2069,14 @@ public
20692069
case CREF(cref = ComponentRef.CREF())
20702070
algorithm
20712071
subs := expandCref2(crefExp.cref);
2072+
2073+
if listEmpty(subs) then
2074+
arrayExp := ARRAY(Type.ARRAY(Type.arrayElementType(crefExp.ty), {Dimension.INTEGER(0)}), {});
2075+
else
2076+
arrayExp := expandCref3(subs, crefExp.cref, Type.arrayElementType(crefExp.ty));
2077+
end if;
20722078
then
2073-
expandCref3(subs, crefExp.cref, Type.arrayElementType(crefExp.ty));
2079+
arrayExp;
20742080

20752081
else crefExp;
20762082
end match;
@@ -2091,7 +2097,7 @@ public
20912097
dims := Type.arrayDims(cref.ty);
20922098
cr_subs := Subscript.expandList(cref.subscripts, dims);
20932099
then
2094-
expandCref2(cref.restCref, cr_subs :: subs);
2100+
if listEmpty(cr_subs) then {} else expandCref2(cref.restCref, cr_subs :: subs);
20952101

20962102
else subs;
20972103
end match;

Compiler/NFFrontEnd/NFScalarize.mo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ algorithm
102102
if Type.isArray(var.ty) then
103103
Variable.VARIABLE(name, ty, binding, vis, attr, ty_attr, cmt, info) := var;
104104
crefs := ComponentRef.scalarize(name);
105+
106+
if listEmpty(crefs) then
107+
return;
108+
end if;
109+
105110
ty := Type.arrayElementType(ty);
106111
(ty_attr_names, ty_attr_iters) := scalarizeTypeAttributes(ty_attr);
107112

Compiler/NFFrontEnd/NFSubscript.mo

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,29 @@ public
303303
protected
304304
Dimension dim;
305305
list<Dimension> rest_dims = dimensions;
306+
list<Subscript> subs;
306307
algorithm
307308
for s in subscripts loop
308309
dim :: rest_dims := rest_dims;
309-
outSubscripts := expand(s, dim) :: outSubscripts;
310+
subs := expand(s, dim);
311+
312+
if listEmpty(subs) then
313+
outSubscripts := {};
314+
return;
315+
else
316+
outSubscripts := subs :: outSubscripts;
317+
end if;
310318
end for;
311319

312320
for d in rest_dims loop
313-
outSubscripts := RangeIterator.map(RangeIterator.fromDim(d), makeIndex) :: outSubscripts;
321+
subs := RangeIterator.map(RangeIterator.fromDim(d), makeIndex);
322+
323+
if listEmpty(subs) then
324+
outSubscripts := {};
325+
return;
326+
else
327+
outSubscripts := subs :: outSubscripts;
328+
end if;
314329
end for;
315330

316331
outSubscripts := listReverse(outSubscripts);

Compiler/Util/List.mo

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6935,8 +6935,12 @@ public function combination<TI>
69356935
protected
69366936
list<list<TI>> elems;
69376937
algorithm
6938-
elems := combination_tail(inElements, {}, {});
6939-
outElements := listReverse(elems);
6938+
if listEmpty(inElements) then
6939+
outElements := {};
6940+
else
6941+
elems := combination_tail(inElements, {}, {});
6942+
outElements := listReverse(elems);
6943+
end if;
69406944
end combination;
69416945

69426946
protected function combination_tail<TI>

0 commit comments

Comments
 (0)