Opened 12 years ago

Last modified 7 years ago

#1822 new defect

Replaceable type cannot unify with itself

Reported by: adabe588@… Owned by: somebody
Priority: high Milestone: Future
Component: Backend Version: trunk
Keywords: typechecking Cc:

Description

This code looks okay to me, but the typechecker disagrees. I'm making a recursive call which causes a type unification error. I have similar code in other places that do not have this issue.

Actual Output:

{true,true,true}
true
""

"[test.mo:17:3-17:27:writable] Error: Type mismatch in assignment in result := Collection.find(next, it) of polymorphic<Element> := polymorphic<$.Collection.Next.Element>
[test.mo:17:3-17:27:writable] Error: Type mismatch in pattern result
actual type:
  polymorphic<Element>
expected type:
  polymorphic<$.Collection.Next.Element>
"

Expected Output:

{true,true,true}
true
""

(infinite loop)

Script:

setCommandLineOptions({"+d=rml,noevalfunc,failtrace","+g=MetaModelica","+showAnnotations"});

loadFile("test.mo");
getErrorString();

Test.test({1,2,3,4});
getErrorString();

Code:

encapsulated package Collection

replaceable type State subtypeof Any;
replaceable type Element subtypeof Any;

partial function Next
  input State state;
  output Element current;
  output State nextState;
end Next;

function find
  input Next next;
  input State it;
  output Element result;
algorithm
  result := find(next, it);
end find;

end Collection;


encapsulated package Test

protected import Collection.{find,Next};

public function firstRest<A>
  input List<A> list;
  output A first;
  output List<A> rest;
algorithm
  (first,rest) := match (list)
    case first :: rest then (first, rest);
 end match;
end firstRest;

function lfind<A>
  input Next next;
  input List<A> list;
  output A result;
algorithm
  result := find(firstRest, list);
end lfind;

function test
  input List<Integer> list;
  output Integer res;
algorithm
  res := lfind(firstRest, list);
end test;

end Test;

Change History (10)

comment:1 Changed 12 years ago by sjoelund.se

This works:

encapsulated package Collection

replaceable type State subtypeof Any;
replaceable type Element subtypeof Any;

partial function Next
  input State state;
  output Element current;
  output State nextState;
end Next;

function find

  partial function Next
    input State state;
    output Element current;
    output State nextState;
  end Next;

  input Next next;
  input State it;
  output Element result;
algorithm
  result := find(next, it);
end find;

end Collection;

The problem is probably somewhere in the unification there is an assumption that any type variable that comes from a scope outside this function cannot be deduced. And it is sort of correct (the Element in Next and the function are *different* Element). I might have a look at this at a later date.

comment:2 Changed 11 years ago by sjoelund.se

  • Milestone changed from 1.9.0 to 1.9.1

Postponed until 1.9.1

comment:3 Changed 10 years ago by sjoelund.se

  • Milestone changed from 1.9.1 to 1.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:4 Changed 10 years ago by sjoelund.se

  • Milestone changed from 1.9.2 to 1.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:5 Changed 9 years ago by sjoelund.se

  • Milestone changed from 1.9.3 to 1.9.4

Moved to new milestone 1.9.4

comment:6 Changed 9 years ago by sjoelund.se

  • Milestone changed from 1.9.4 to 1.9.5

Milestone pushed to 1.9.5

comment:7 Changed 9 years ago by sjoelund.se

  • Milestone changed from 1.9.5 to 1.10.0

Milestone renamed

comment:8 Changed 8 years ago by sjoelund.se

  • Milestone changed from 1.10.0 to 1.11.0

Ticket retargeted after milestone closed

comment:9 Changed 8 years ago by sjoelund.se

  • Milestone changed from 1.11.0 to 1.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:10 Changed 7 years ago by casella

  • Milestone changed from 1.12.0 to Future

The milestone of this ticket has been reassigned to "Future".

If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.

If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".

In both cases, a short informative comment would be welcome.

Note: See TracTickets for help on using tickets.