Opened 4 years ago

Last modified 3 years ago

#6213 accepted defect

Lookup in wrong scope when redeclaring function field in a function

Reported by: Martin Sjölund Owned by: Per Östlund
Priority: high Milestone:
Component: New Instantiation Version: v1.17.0-dev
Keywords: Cc:

Description

Modelica_LinearSystems2.Controller.Examples.DiscretizationSeries has some code with the same error as:

record R
  Real x[:];
end R;
function f
  input Integer n;
  output R r(redeclare Real x[n]);
end f;
model M
  Real x[:] = f(3);
end M;

Change History (5)

comment:1 by Per Östlund, 4 years ago

Status: newaccepted

The issue is that we don't save the scope that dimensions are declared in, so when we later try to instantiate it we don't know that it came from a redeclare and should actually be looked up inside f. We need to save the scope in the same way that we currently handle bindings and use that instead when instantiating dimensions.

Last edited 4 years ago by Per Östlund (previous) (diff)

comment:2 by Francesco Casella, 4 years ago

Component: FrontendNew Instantiation

I guess after 1.17.0 we can start to use "Frontend" again. At least, let's wait until we are sure that we can transition to the NF safely.

comment:3 by Per Östlund, 4 years ago

Fixed in PR 6938, but it still doesn't work properly.

The lookup now works as it should but the type of the function call will be record R(Real[n]), i.e. we apply the redeclare correctly but don't evaluate n in the return type. The issue is that complex types are represented by an instance node, so we can't currently change a complex output type without also affecting the type of all other calls of that function. We need to either clone the instance nodes in complex types when typing a function call, which I'm not sure is a good idea, or change how we represent types in this situation.

comment:4 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:5 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.