Opened 12 years ago
Last modified 7 years ago
#1822 new defect
Replaceable type cannot unify with itself
Reported by: | 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 by , 12 years ago
comment:3 by , 10 years ago
Milestone: | 1.9.1 → 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 by , 10 years ago
Milestone: | 1.9.2 → 1.9.3 |
---|
Milestone changed to 1.9.3 since 1.9.2 was released.
comment:9 by , 8 years ago
Milestone: | 1.11.0 → 1.12.0 |
---|
Milestone moved to 1.12.0 due to 1.11.0 already being released.
comment:10 by , 7 years ago
Milestone: | 1.12.0 → 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.
This works:
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.