Immutable and mutable? are covariant on their inner types

Whereas [mutable T] is invariant with respect to T, [T] and [mutable? T]
are covariant with respect to T.
This commit is contained in:
Brian Anderson 2011-10-18 10:35:33 -07:00
parent 71a4a66135
commit 314c011d71
3 changed files with 36 additions and 3 deletions

View file

@ -1947,9 +1947,16 @@ mod unify {
variance: variance) ->
option::t<(ast::mutability, variance)> {
// If you're unifying mutability then the thing inside
// will be invariant on anything it contains
let newvariance = variance_transform(variance, invariant);
// If you're unifying on something mutable then we have to
// be invariant on the inner type
let newvariance = alt expected {
ast::mut. {
variance_transform(variance, invariant)
}
_ {
variance_transform(variance, covariant)
}
};
if expected == actual { ret some((expected, newvariance)); }
if variance == covariant {