Opened 7 years ago

Closed 7 years ago

#4754 closed defect (invalid)

Tuple-returning calls are mistyped in if-equations

Reported by: Per Östlund Owned by: Martin Sjölund
Priority: high Milestone:
Component: MetaModelica Version: v1.13.0-dev-nightly
Keywords: Cc:

Description

This script:

setCommandLineOptions("-g=MetaModelica");
loadString("
  function f
    input Integer i;
    output Real x;
    output Real y;
  algorithm
    x := i * 2;
    y := i * 3;
  end f;

  function test
    input Integer i;
    output Real x;
    output Real y;
  algorithm
    (x, y) := if i > 0 then f(1) else f(2);
  end test;
");
test(1);
getErrorString();

gives the error message:

Error: Invalid pattern: (x, y) of type Real
Error: Tuple assignment only allowed when rhs is function call (in if i > 0 then (2.0, 3.0)[1] else (4.0, 6.0)[1]).

The second error is only printed due to a matchcontinue, but it does show that the compiler has decided to only use the first element of the tuples for some reason. If the if-expression is changed to something like if i > 0 then (2.0, 3.0) else (4.0, 6.0); then it works fine.

Change History (2)

comment:1 by Per Östlund, 7 years ago

Component: *unknown*MetaModelica
Owner: changed from somebody to Martin Sjölund
Version: v1.13.0-dev-nightly

comment:2 by Martin Sjölund, 7 years ago

Milestone: Future
Resolution: invalid
Status: newclosed

This is not an error. It's not an if-equation but an if-expression. And in composite expressions only the first element of the tuple is returned: the type of the if-expression in this case is indeed Real and nothing else.

Note: See TracTickets for help on using tickets.