-
Notifications
You must be signed in to change notification settings - Fork 1.1k
type parameter inference behaves unexpectedly when a type parameter is used in a contravariant position #718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Arguably, dotty is right here. In this case, the type parameter
so it is picked. |
But the spec says:
And the problem is not specific to class Foo[-T]
trait X
trait Y extends X
object Test {
def foo[A >: Y](x: Foo[A]): Int = 0
foo(new Foo[X])
}
|
The type On Thu, Jul 9, 2015 at 9:59 AM, Guillaume Martres notifications@github.com
Martin Odersky |
It seems deliberate: https://github.com/scala/scala/blob/2.11.x/src/reflect/scala/reflect/internal/tpe/TypeConstraints.scala#L188-L189 used indirectly by https://github.com/scala/scala/blob/2.11.x/src/compiler/scala/tools/nsc/typechecker/Infer.scala#L550 And the behavior of dotty seems more surprising to me than the behavior of scalac here: import scala.reflect.ClassTag
import scala.reflect.classTag
object Test {
def getParamType[T: ClassTag](x: T => Int) = println(classTag[T])
def main(args: Array[String]): Unit = {
getParamType((x: Int) => x) // dotty: Nothing, scalac: Int
}
} |
It's Cecilia Bigler. http://ic.epfl.ch/computer-science/bachelor
On Thu, Jul 9, 2015 at 11:31 AM, Guillaume Martres <notifications@github.com
Martin Odersky |
@smarter, Though dotty behavior here seems unintuitive, the types in all examples that you give are the minimal types that are enough to typecheck. I find it easier to reason about such behavior, compared to the behavior of Scalac, where treatment of |
Fixed by #799. |
scalac
infersA
to beInt
:But dotty infers
A
to beNothing
:This is probably not what we want, especially for function types.
The text was updated successfully, but these errors were encountered: