Opened 6 years ago
Last modified 6 years ago
#5526 new defect
MetaModelica: loop over list<Integer> — at Initial Version
Reported by: | Owned by: | Lennart Ochel | |
---|---|---|---|
Priority: | normal | Milestone: | Future |
Component: | Code Generation | Version: | v1.14.0-dev-nightly |
Keywords: | Cc: |
Description
Using an Integer from a list<Integer> as array index will give the wrong array component, if the list is part of a record.
Example:
uniontype Index
record INDEX
list<Integer> idx;
end INDEX;
end Index;
uniontype Compo
record COMPO
array<Real> co;
end COMPO;
end Compo;
Supposed we have a Compo called compo and an Index called index, the for loop gives wrong array components:
for k in index.idx loop
print(String(k));
r := compo.co[k];
end for;
The print command gives the correct number, but k as array index
seems to have twice the value of the list member. So if it exceeds the array bounds we will see an error otherwise r has a wrong value.
A known workaround: Assign k to an integer variable and use it instead of k or do an integer operation with k at the place where you use k. For instance r := compo.co[k+0].