Opened 5 years ago

Last modified 3 years ago

#5730 new defect

Issue with operator record constructors in NF

Reported by: Francesco Casella Owned by: Per Östlund
Priority: high Milestone:
Component: New Instantiation Version:
Keywords: Cc:

Description

Please check Modelica_LinearSystems2.Controller.Examples.InverseDoublePendulumWithObserver. The NF reports

[Modelica_LinearSystems2 2.3.5/DiscreteStateSpace.mo:26:5-29:54:writable]
Error: Base class Modelica_LinearSystems2.DiscreteTransferFunction.Conversion.toDiscreteStateSpace
not found in scope 'constructor'.

The sought-after function is defined here.

The scope of constructor is encapsulated. However, Section 5.3.1 of the Specification states that lookup is stopped for simple names, not composed using dot notation.

Change History (11)

in reply to:  description comment:1 by Per Östlund, 5 years ago

Replying to casella:

The scope of constructor is encapsulated. However, Section 5.3.1 of the Specification states that lookup is stopped for simple names, not composed using dot notation.

The first part of a composite name is looked up using the rules for simple names, so that the name is composite doesn't matter when encapsulated is concerned. The constructor contains the necessary imports for finding the name though, so it should probably work.

comment:2 by Francesco Casella, 5 years ago

Yeah, I missed the import statements.

comment:3 by Per Östlund, 5 years ago

The ticket discription is actually a bit misleading, the first error that occurs is:

[DiscreteTransferFunction.mo:67:75-68:105:writable] Error: Variable p not found in scope DiscreteTransferFunction.

The line the error refers to is:

output DiscreteTransferFunction dtf(redeclare Real n[size(z, 1)+1],
                                    redeclare Real d[size(p, 1)+1]);

It seems like the dimensions of the redeclare elements is instantiated using the wrong scope here. Here's a minimal model that shows the same issue (and which doesn't work with the OF either):

model A
  Real x[:];
end A;

model M
  parameter Integer n = 2;
  A a(redeclare Real x[n]);
end M;

in reply to:  3 ; comment:4 by Francesco Casella, 5 years ago

Replying to perost:

The ticket discription is actually a bit misleading, the first error that occurs is:

[DiscreteTransferFunction.mo:67:75-68:105:writable] Error: Variable p not found in scope DiscreteTransferFunction.

Regarding this issue, it is not clear to me why the compiler continues instead of just quitting after the first error.

It seems like the dimensions of the redeclare elements is instantiated using the wrong scope here. Here's a minimal model that shows the same issue (and which doesn't work with the OF either):

model A
  Real x[:];
end A;

model M
  parameter Integer n = 2;
  A a(redeclare Real x[n]);
end M;

I tried to figure out the scope of n in the redeclaration from the specification text. I guess that involves the instance tree and the class tree, but that's a bit too technical for me. Can you help me with that?

How would you fix this? I would use this pattern:

model A
  parameter Integer n;
  Real x[n];
end A;

model M
  parameter Integer n = 2;
  A a(n = n);
end M;

in reply to:  4 comment:5 by Per Östlund, 5 years ago

Replying to casella:

Regarding this issue, it is not clear to me why the compiler continues instead of just quitting after the first error.

It probably tries to instantiate some class while doing lookup which fails due to the first error, then it prints the second error because the lookup failed.

Replying to casella:

I tried to figure out the scope of n in the redeclaration from the specification text. I guess that involves the instance tree and the class tree, but that's a bit too technical for me. Can you help me with that?

How would you fix this? I would use this pattern:

model A
  parameter Integer n;
  Real x[n];
end A;

model M
  parameter Integer n = 2;
  A a(n = n);
end M;

If you want to work around the issue I guess you can do it like that. But ultimately it's a compiler issue, n should be looked up in the scope of the modifier (M) and not in the scope of the redeclared element (A).

comment:6 by Francesco Casella, 5 years ago

Should I open a separate ticket for the lookup of n?

in reply to:  6 comment:7 by Per Östlund, 5 years ago

Replying to casella:

Should I open a separate ticket for the lookup of n?

If you want to, but it's not really necessary for my sake.

comment:8 by Francesco Casella, 5 years ago

OK, I stand by for both fixes then :)

comment:9 by Francesco Casella, 4 years ago

Milestone: 1.16.01.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:10 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:11 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.