Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency in treating array dimensions in modifiers #1251

Closed
modelica-trac-importer opened this issue Nov 4, 2018 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@modelica-trac-importer
Copy link
Collaborator

Reported by petfr on 18 Aug 2013 10:23 UTC
A design goal and property in Modelica is that array
dimensions should be possible either on the type or
on the component, i.e., both of the following are allowed:

Real[20] vec;
Real vec[20];

This language rule is broken for modifiers in the current version
of Modelica, MS 3.2.2, where the form vec[20] is allowed
but not Real[20]. This inconsistenly just recently caused
me a lot of confusion. The language grammar should be updated
to consistenly allow both forms.

Current grammar:
element_replaceable:
replaceable ( short_class_definition | component_clause1) [constraining_clause]

component_clause1:
type_prefix type_specifier component_declaration1

type_prefix: flow | stream | ...
type_specifier: name
component_declaration1: declaration comment
declaration: IDENT [ array_subscripts ] [ modification ]

Example which is accepted by current grammar and by Dymola:

package testredeclare

class C3
Real x1;
Real[:] vec;
end C3;

class C4 = C3(redeclare parameter Real x1, redeclare Real vec[20]);

end testredeclare;

Example which is not accepted by current grammar:

package testredeclare

class C3
Real x1;
Real[:] vec;
end C3;

class C4 = C3(redeclare parameter Real x1, redeclare Real[20] vec);

end testredeclare;


Migrated-From: https://trac.modelica.org/Modelica/ticket/1251

@modelica-trac-importer modelica-trac-importer added the bug Something isn't working label Nov 4, 2018
@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 24 Sep 2013 08:27 UTC
Language group:

Consider:

type Vec=Real[:];
type Vec2=Real[2];
class C3
  Real x1;
  Vec  x2[:];
  Vec [:] x3[:];
end C3;

Currently C3(redeclare Vec2 x2); means keep : from original declaration, i.e. Vec2 x2[:] and C3(redeclare Real x2[3,2]); is not allowed, since the "type" should have same dimensions as original declaration (end of section 7.3.2).

And C3(redeclare Vec x3[2]); is not allowed; i.e. the type-dimensions are not allowed to be "inherited" independently (end of 7.3.2). Either give all array dimensions or none.

So view Real[4] x[2] as syntactic sugar for Real x[2,4];; and either give all array dimensions or none; and thus logical to allow that in redeclare as well.

Conclusion: State that just syntactic sugar and allow in redeclare as well.
Agreement.
Poll: Include in 3.3r1?
Agree: 0
Against: 1
Abstain: 5
Conclusion: needs more work.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 1 Mar 2017 14:11 UTC
In 7.3 state that:
Replaceable component array declarations with array sizes on the left of the component are seen as syntactic sugar for having all arrays sizes on the right of the component; and thus can be redeclared in a consistent way.

Example:

  model M
    replaceable Real [4] x[2];
  end M;
  M m(redeclare Modelica.SIunits.Length x[2,4]);

Agreement by acclamation.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 14 Mar 2017 10:34 UTC
Resolved in r9681

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants