Is Collection(T) covariant on T? [message #1744472] |
Tue, 27 September 2016 06:51  |
Eclipse User |
|
|
|
Hi!
According to the Section 11.7.5 of the OCL Specification 2.4 Sequence type has the following operation:
including(object : T) : Sequence(T)
I expect that the following expression will return invalid value.
Sequence{1, 2, 3}->including('string')
Because operation including(String) is not defined for Sequence(Integer). I expect that type T of the argument must conform to the type T of the source Sequence(T). Also the resulting and source collections will have the same Sequence(T) type.
But the result of the expression is the Sequence{1,2,3,'string'} with a Sequence(OclAny) type.
Even the following expression has the same result:
let coll : Sequence(Integer) = Sequence{1,2,3} in coll->including('string')
Is it true that OCL Sequence(T) is covariant on T? Integer is a subtype of OclAny. So Sequence(Integer) is a subtype of Sequence(OclAny). And so the operation including(OclAny) is defined for Sequence(Integer)?
[Updated on: Tue, 27 September 2016 06:52] by Moderator
|
|
|
|
|
|
Re: Is Collection(T) covariant on T? [message #1744491 is a reply to message #1744479] |
Tue, 27 September 2016 08:29  |
Eclipse User |
|
|
|
Hi
Agree and agree. Which is why substantial improvements are required to the OCL specification, but we need the models and prototype to move on from the current manual best endeavors.
The first example gives me:
The 'Variable::CompatibleInitialiserType' constraint is violated for 'intCollection : Sequence(Integer) = realCollection'
in the Interactive Xtext OCL Console.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.03482 seconds