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

Heterogeneous arrays with non-record classes #3414

Closed
HNeitzel opened this issue Sep 12, 2023 · 2 comments · Fixed by #3421
Closed

Heterogeneous arrays with non-record classes #3414

HNeitzel opened this issue Sep 12, 2023 · 2 comments · Fixed by #3421

Comments

@HNeitzel
Copy link

The standard states at the start of ch. 10 (emphasis mine)

A non-record array can be regarded as a collection of type compatible values. An array of records may contain scalar record values whose elements differ in their dimension sizes, but apart from that they must be of the same type. [...] An array of arrays must have the same dimension sizes for all of the arrays (with the same exception for records)

What is the meaning of record in this case? Does it refer only to record type classes, or does it mean any composite, such as model, block or generic class? The tools I have tried seem to take the latter approach, e.g. OpenModelica accepts the following:

class A
  parameter Integer N;
  Real[N] x;
equation
  for i loop
    x[i] = 0;
  end for;
end A;
model B
  A a[3](N = 1:3);
end B;

If this is indeed the intention, it might be helpful to clarify this paragraph.

@HansOlsson
Copy link
Collaborator

HansOlsson commented Sep 12, 2023

That example should be legal. The record part is that it would also be legal if A were a record.

Note that the introductions to the chapters are non-normative, so it is better to view this as an explanation than as a restriction.

As an explanation it is a bit odd: it would be highly relevant if we had the possibility to introduce heterogenous redeclarations for arrays (and then there should be something normative), but that is not legal at the moment. Similarly the array of array part is redundant with the rectangular case. However, the omitted ... part is relevant as it indicates how arrays with different sizes can be used (10.6.9 Slice Operation - added: or rather component reference in 3.2).

And even if we don't have heterogenous redeclarations there is also the possibility of conditional components in A - e.g. someone added parameter Boolean b=true if N>2;. That is legal for a non-record, but for records I have problems seeing the use-case. And in general conditional components in records are so weird that we might forbid it completely.

@HNeitzel
Copy link
Author

Thank you for the clarification. I was mainly confused why emphasis was put on the array of records when a heterogenous array can arise from other sources as well (like differently parameterised array size or conditional components). The current wording gave me the impression that records are the only source of heterogenous arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants