Opened 13 years ago

Last modified 9 years ago

#1628 new defect

Subscripting jagged arrays give errors

Reported by: Martin Sjölund Owned by: Martin Sjölund
Priority: high Milestone: Future
Component: Version:
Keywords: Cc: Martin Sjölund, Per Östlund

Description

OpenModelica thinks n[2].r has dimension 3. Works in Dymola:

model N
  parameter Integer n;
  Real r[n];
end N;

model M
  N[2] n(n = {3,4});
equation 
  n[1].r = {1,2,3};
  n[2].r = {4,5,6,7};
end M;

Also try to fix:

model M
  N[2] n(n = {3,4});
equation
  n[:].r = {{1,2,3},{4,5,6}};
end M;

(It succeeds but should not!)

Change History (3)

comment:1 by Per Östlund, 13 years ago

This doesn't really have anything to do with jagged arrays. It's a problem with our current environment, which doesn't handle arrays of complex components well. When we elaborate the equations we need to look up n[1].r or n[2].r, but n is stored in the environment as a variable of array complex type. It then has it's own environment since it's complex, which contains n and r from N. We thus have only one instance of n.n and n.r in the environment, which for some reason is n[1].n and n[1].r. So the following model is also instantiated wrongly, giving both j[1] and j[2] the value 3:

model M
  constant Integer i;
end M;

model M2
  M m[2](i = {3, 4});
  Integer j[2];
equation
  j = m.i;
end M2;

This might be a bit tricky to fix.

comment:2 by Martin Sjölund, 13 years ago

Also, this one is fun (and not handled by Dymola):

model M
  N[2] n(n = {3,4});
  N[2] m(n = {3,4});
equation 
  n[1].r = {1,1,1};
  n[2].r = {1,1,1,1};
  n[:].r = 2*m[:].r;
end M;

comment:3 by Dietmar Winkler, 9 years ago

Milestone: Future
Note: See TracTickets for help on using tickets.