Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#2779 closed defect (fixed)

Indexing with zero gives no error message

Reported by: Peter Aronsson Owned by: Per Östlund
Priority: normal Milestone: 1.9.1
Component: Frontend Version: trunk
Keywords: Cc:

Description

Consider this example.

model Experiment3
  Modelica.Blocks.Sources.CombiTimeTable combiTimeTable2(fileName="foo.mat");
  Modelica.Blocks.Math.Gain gain1(k=1);
equation 
  connect(gain1.u,combiTimeTable2.y[0]);
end Experiment3;

This should give an error since it is not allowed to index with zero.
This was tested a long time ago on 1.8.1 and it did give an error message, but apparently not true anymore (tested on 1.9.1 beta2)

Change History (6)

comment:1 by Martin Sjölund, 10 years ago

Owner: changed from somebody to Per Östlund
Status: newassigned

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

Consider the following:

function f
  input Real r[1];
  input Boolean b;
  output Real x = if b then r[0] else r[1];
algorithm 
end f;

Dymola says that function is OK. So we need to allow it. We handle models in the same way...

model M
  Real r[1] = fill(1,1);
  parameter Boolean b = false;
  Real x = if b then r[0] else r[1];
end M;

Dymola does not like that model though, but since you need to handle the first case...

It makes sense to check these things in the backend or runtime. Since illegal expressions are sometimes allowed, we need to handle them in some way. Maybe by making the expression become DAE.FAIL(errorMessage) or something so the backend can produce the original error if branch selection chooses a bad branch (or the subscript is not used in a branch; something elabExp does not know about).

comment:3 by Peter Aronsson, 10 years ago

I agree that the case above could be checked during runtime. But the example in the report is indexing with zero in a connection set, and that -must- be checked by the frontend.

comment:4 by Martin Sjölund, 10 years ago

Well, it doesn't have to be checked in the front-end. The back-end could also catch the error in this case. But I agree it is nicer if errors are caught early.

comment:5 by Per Östlund, 10 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r21937. I implemented some more error checking for array subscripts, and check index bounds in connects. There's many other places where it might be good to check index bounds too, but it's hard to know where it's safe to do so with how the compiler is currently structured.

comment:6 by Per Östlund, 10 years ago

Apologies, seems like I only committed the testsuite changes in r21937. Actual fix in r21945.

Note: See TracTickets for help on using tickets.