modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Creative Commons Attribution Share Alike 4.0 International
104 stars 40 forks source link

Redeclaration of dimensions #492

Closed modelica-trac-importer closed 6 years ago

modelica-trac-importer commented 6 years ago

Reported by stefanv on 1 Feb 2011 15:11 UTC Section 7.3 of the Modelica 3.2 specification states that if a redeclaration does not specify the dimensions, then the dimensions are inherited from the original. However, dimensions are listed as only being valid for components, not classes. Is this really the case? Note that the following redeclaration is syntactically valid:

extends A( redeclare type T = R[2] );

What needs clarification is:

  1. Is the above actually allowed?
  2. If so, does the dimension ![2] replace the dimension inherent in T, or is it appended?
  3. If the ![2] above were omitted, would the new T inherit the dimension from the original T?

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

modelica-trac-importer commented 6 years ago

Comment by choeger on 1 Feb 2011 19:14 UTC Replying to [ticket:492 stefanv]:

Section 7.3 of the Modelica 3.2 specification states that if a redeclaration does not specify the dimensions, then the dimensions are inherited from the original. However, dimensions are listed as only being valid for components, not classes. Is this really the case? Note that the following redeclaration is syntactically valid:

I found the following sentence:

Similarly the type used in a redeclaration must have the same number of dimensions as the type of redeclared element.

My informal interpretation would be (considering the subtype restriction): you may increase the array dimension but not decrease or omit it. That depends on wether you count the array dimension as part of the type or not. If not, you need to simply redeclare an array subtype.

modelica-trac-importer commented 6 years ago

Comment by stefanv on 1 Feb 2011 19:30 UTC Okay, so that suggests that the dimension ![2] in my original example is only valid if type T originally had the same number of dimensions as type R![2]. So, if R were a scalar type, then the original T must be a one-dimension array. If R were already a one-dimensional array, then R[2] has two dimensions, and so the original T would also have to have had two dimensions.

You wrote, "you may increase the array dimension but not decrease or omit it."

I don't think that's quite right. You may not increase the number of dimensions, but you may increase or decrease the size of each dimension. You may also omit the dimensions, in which case it is inherited from the original type.

Now I wonder, if the original type had 2 dimensions, but the redeclaration had only 1, does that one redeclare the last dimension of the original type, or is that simply not allowed?

modelica-trac-importer commented 6 years ago

Comment by choeger on 1 Feb 2011 20:09 UTC Replying to [comment:2 stefanv]:

I don't think that's quite right. You may not increase the number of dimensions, but you may increase or decrease the size of each dimension. You may also omit the dimensions, in which case it is inherited from the original type.

I would really like to know where you got that from. This would mean an implicit type cast. Of course it would be possible but it seems a little bit strange.

Now I wonder, if the original type had 2 dimensions, but the redeclaration had only 1, does that one redeclare the last dimension of the original type, or is that simply not allowed?

IMO a one-dimensional array can never be a subtype of a 2-dimensional one (of the same scalar type). Thereofore it should be an error.

modelica-trac-importer commented 6 years ago

Comment by stefanv on 1 Feb 2011 20:16 UTC Inheriting the dimensions from the original type if omitted in the redeclaration is specifically mentioned in section 7.3 of the specification (last item in the second list at the top of page 72).

Specifying only one dimension when the original type had two is analogous to specifying zero dimensions when the original type had one. In conjunction with the inheritance of dimensions rule above, it begs the question as to whether this is allowed.

modelica-trac-importer commented 6 years ago

Comment by choeger on 1 Feb 2011 20:36 UTC Ah, there it is. Is that used anywhere ;)?

As far as I can see, this applies to components only (not type redeclarations).

Additionally, it is stated that this rule only applies, if there is no prefix. So redeclaring a component's type without giving any array dimensions will use the inherited array dimensions (redeclaration then only affects the base type).

modelica-trac-importer commented 6 years ago

Comment by stefanv on 1 Feb 2011 21:08 UTC

As far as I can see, this applies to components only (not type redeclarations).

That was the whole point of this ticket. Does it apply to classes (i.e. is it an error in section 7.3)? The syntax does allow it to be written to apply to classes. In fact, the syntax goes to great pains to restrict what is allowed when redeclaring a component, so the fact that it does not do so for redeclaring a class suggests that there are no such restrictions intended.

Additionally, it is stated that this rule only applies, if there is no prefix.

It then depends on whether you consider each dimension to be a separate prefix (ignoring for the moment that dimensions are not a prefix at all).

modelica-trac-importer commented 6 years ago

Comment by HansOlsson on 24 Mar 2011 10:27 UTC Conclusions: Well-defined as written (assuming R had 1 array dimension originally).

Proposal 1: Without array dimensions it would be consistent to keep the ones from the original declaration (for classes as for components). I.e. move 'array dimensions' to first list in section 7.3.

Problem is 'redeclare type A=B' where 'B' is an array type.

0 in favor, 4 against.

Proposal 2: Array dimensions for types are not inherited. Have to repeat them in the few cases it is needed (subject to normal subtype restrictions), it will otherwise be a type error. 5 in favor, 0 against.

Proposal 3: No array dimensions allowed in redeclare of types.

3 in favor, 1 against. --- Will add proposal 2 to specification.

modelica-trac-importer commented 6 years ago

Modified by HansOlsson on 24 Mar 2011 12:49 UTC

modelica-trac-importer commented 6 years ago

Modified by dietmarw on 24 Mar 2011 14:23 UTC

modelica-trac-importer commented 6 years ago

Modified by hansolsson on 28 Sep 2011 12:57 UTC

modelica-trac-importer commented 6 years ago

Modified by dietmarw on 28 Sep 2011 20:46 UTC