Opened 6 years ago
Last modified 6 years ago
#5526 new defect
MetaModelica: loop over list<Integer>
Reported by: | Owned by: | Lennart Ochel | |
---|---|---|---|
Priority: | normal | Milestone: | Future |
Component: | Code Generation | Version: | v1.14.0-dev-nightly |
Keywords: | Cc: |
Description (last modified by )
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].
Change History (5)
comment:1 by , 6 years ago
comment:4 by , 6 years ago
It might solve the problem, but we still have bugs in the MetaModelica compiler. Probably open tickets for this particular problem though...
Does it work if you use arrayGet() instead of
[]
indexing (which is not part of MetaModelica 1.0)?