Created
February 7, 2013 23:43
-
-
Save JamesIry/4735290 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> object Test { | |
| | |
| class Inv[T] | |
| | |
| def foo[S](interface: Inv[_ >: S], implementation: Inv[S]) {} | |
| | |
| def bar[R, T <: R](interface: Inv[R], impl: Inv[T]) { | |
| //foo[T](interface, impl) | |
| foo(interface, impl) // Compilation Error | |
| // Inv[R] <: Inv[_ >: S] | |
| // Inv[T] <: Inv[S] | |
| // ---------------------- | |
| // R >: S | |
| // T == S | |
| } | |
| | |
| } | |
<console>:15: error: type mismatch; | |
found : Test.Inv[T] | |
required: Test.Inv[R] | |
Note: T <: R, but class Inv is invariant in type T. | |
You may wish to define T as +T instead. (SLS 4.5) | |
foo(interface, impl) // Compilation Error | |
^ | |
scala> def f[T](x1: Set[T]) = () => new { def apply(x2: Set[_ <: T]) = List(x1, x2) } | |
<console>:7: error: type mismatch; | |
found : AnyRef{def apply(x2: Set[_ <: T]): List[scala.collection.immutable.Set[_ >: _$1 <: T]] forSome { type _$1 <: T }} | |
required: AnyRef{def apply(x2: Set[_ <: T]): List[scala.collection.immutable.Set[_ >: _$1(in method apply) <: T]] forSome { type _$1(in method apply) <: T }} | |
def f[T](x1: Set[T]) = () => new { def apply(x2: Set[_ <: T]) = List(x1, x2) } | |
^ | |
scala> object Bug { | |
| trait H[F[_]] | |
| def f[F[_], T, FT <: F[T]](h : H[F]) = 1 | |
| f(new H[Set]{}) | |
| } | |
<console>:10: error: inferred kinds of the type arguments ({},Nothing,Nothing) do not conform to the expected kinds of the type parameters (type F,type T,type FT). | |
{}'s type parameters do not match type F's expected parameters: | |
scala has no type parameters, but type F has one | |
f(new H[Set]{}) | |
^ | |
<console>:10: error: type mismatch; | |
found : Bug.H[Set] | |
required: Bug.H[F] | |
f(new H[Set]{}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment