modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Other
94 stars 41 forks source link

Type compatibility of array expressions within if-expressions #2165

Open modelica-trac-importer opened 5 years ago

modelica-trac-importer commented 5 years ago

Reported by stefanv on 6 Mar 2017 18:06 UTC Section 6.6 of the 3.3 specification states:

If A is an array expression then B must also be an array expression, and ndims(A)=ndims(B). The type compatible expression an array expression with elements compatible with the elements of both A and B. If both size(A) and size(B) are known and size(A)=size(B) then this defines the size of the type compatible expression, otherwise the size of the expression is not known until the expression is about to be evaluated. In case of an if-expression the size of the type compatible expression is defined based on the branch selected, and for other cases size(A)=size(B) must hold at this point..

There are three issues with this, one that needs further clarification, and two that are just grammatical:

(I have put this down for MLS 3.4 since there is not yet a Design94 milestone.)


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

modelica-trac-importer commented 5 years ago

Comment by hansolsson on 14 Mar 2017 15:08 UTC The second sentence, "The type compatible expression an array expression with elements compatible with the elements of both A and B.", seems to be missing some word(s).

I believe the minimal missing word is "is":

"The type compatible expression is an array expression with elements compatible with the elements of both A and B." -- I added this and corrected the 3rd issue in r9685 (seemed like simple typos). However, the first issue still remains.

HansOlsson commented 3 years ago

After thinking more, I'm not certain the first issue should be changed in the indicated way.

Obviously if you declare

model M
  Real x[:]=if ... then {1,2} else {1,2,3};
end M;

then the if-condition must be evaluated to a specific size for the array.

However, we also have arrays sent to functions, and expressions inside functions - where you could have:

function foo
  input Integer n;
  input Real a,b;
protected
  Real x[n]=if n==1 then {(a+b)/2} else linspace(a,b,n);
...
end foo;

I don't see that n being non-parametric would be a problem inside the function.

Obviously this might be discussed, and depending on decision clarified/changed - but I don't see it for 3.5.

HansOlsson commented 3 years ago

This is also part of #2494 - which highlights an issue with the assumed resolution.