Opened 11 years ago

Last modified 6 years ago

#2276 reopened defect

detecting size mismatch for output arguments in functions

Reported by: Willi Braun Owned by: somebody
Priority: normal Milestone: 2.1.0
Component: New Instantiation Version: trunk
Keywords: Cc: Per Östlund

Description

Following model runs into an segmentation fault, since we set the unknown size to 99.

model test1
  function f1
    input Real u;
    output Real y[:];
  algorithm
    for i in 1:5 loop
      y[i] := i+u;
    end for;
  end f1;
  Real z[5];
equation
  z = f1(time);
end test1;

But it should end up with an flatting error like the constant case.

model test1
  function f1
    output Real y[:]; // unknown size
  algorithm
    for i in 1:5 loop
      y[i] := i;
    end for;
  end f1;
  Real z[5];
equation
  z = f1();
end test1;
[<interactive>:50:3-50:11:writable] Error: Array equation has unknown size in {z[1], z[2], z[3], z[4], z[5]}={1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}.
[<interactive>:50:3-50:11:writable] Error: Type mismatch in equation {z[1], z[2], z[3], z[4], z[5]}={1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0} of type Real[5]=Real[:].
Error: Error occurred while flattening model test1

Change History (12)

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

Milestone: 1.9.01.9.1

Postponed until 1.9.1

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

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

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

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

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

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:5 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:6 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:7 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:8 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:9 by Francesco Casella, 7 years ago

Cc: Per Östlund added
Component: FrontendNew Instantiation
Milestone: 1.12.02.0.0
Resolution: worksforme
Status: newclosed

With the new instantiation the following error is generated:

[1] 01:34:08 Translation Error
[test1: 3:5-3:21]: Failed to deduce dimension 1 of y due to missing binding equation.

comment:10 by Per Östlund, 7 years ago

Resolution: worksforme
Status: closedreopened

That error is due to the function being instantiated like a normal class, and wrong since function parameters are allowed to have unknown size. I'm not quite sure what the expected behaviour here actually is, the specification is very vague regarding unknown dimensions.

We should definitely check that the function parameter is assigned to correctly, i.e. given a size by assignment in the algorithm. Handling outputs with unknown size is a bit tricky since they can change size according to what's assigned to them, so we might have to just forbid using such functions like this.

comment:12 by Francesco Casella, 6 years ago

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