Skip to content

Type incompatible if-expressions whose condition depends on function input #2494

@perost

Description

@perost

Modelica.Mechanics.MultiBody.Frames.TransformationMatrices.smallRotation is currently declared like this:

function smallRotation 
  extends Modelica.Icons.Function;
  input TransformationMatrices.Orientation T;
  input Boolean withResidues = false;
  output Modelica.SIunits.Angle[if withResidues then 6 else 3] phi;
algorithm
  phi := if withResidues then {T[2, 3], -T[1, 3], T[1, 2], T[1, 1] - 1, T[2, 2] - 1, T[1, 1] * T[2, 2] - T[2, 1] * T[1, 2] - 1} else {T[2, 3], -T[1, 3], T[1, 2]};
  annotation(Inline = true); 
end smallRotation;

The specification currently just says that the two branches of an if-expression must be type compatible, but I believe it's generally agreed that this does not need to be the case if the condition can be evaluated (see #2165).

But in this case we have type incompatible branches and a condition that's a function input. Is this supposed to be allowed? And if so, how is it supposed to be handled?

Metadata

Metadata

Assignees

Labels

duplicateThis issue or pull request already exists

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions