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
Type inference fails to determine type parameter of superclass #2272
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2272?orig=1 |
@adriaanm said: It works if you define implicit def stringer[I](a: F[I]) = a.get.toString |
@dlwh said: You're right that the example would work with that solution, but this is just a simplified test case. In reality, I have a type F[I] that has many subtypes, and I really want to define an implicit def foo[I,Fx<:F[I]](t: Fx): Wrapper[I,Fx] . For most things I can do foo[Fx<:F[_]], but that solution runs into a few other limitations that I'm trying to simplify into something I can turn into a bug report. |
@odersky said: |
@adriaanm said: dhcp-10-9-32-075:tmp adriaan$$ /Users/adriaan/git/scala-mirror/build/quick/bin/scala
Welcome to Scala version 2.8.0.r0-b20090826112135 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_13).
Type in expressions to have them evaluated.
Type :help for more information.
scala> trait F[I]
defined trait F
scala> class FInt extends F[Int]
defined class FInt
scala> class FString extends F[String]
defined class FString
scala> class Wrapper[I, Fx](implicit val w: Fx <:< F[I])
defined class Wrapper
scala> implicit def foo[Fx, I](t: Fx)(implicit w: Fx <:< F[I]): Wrapper[I,Fx] = null.asInstanceOf[Wrapper[I,Fx]]
foo: [Fx,I](t: Fx)(implicit w: <:<[Fx,F[I]])Wrapper[I,Fx]
scala> foo(new FInt)
res1: Wrapper[Int,FInt] = null Note the inferred return type for
sealed abstract class <:<[-From, +To] extends (From => To)
implicit def conforms[A]: A <:< A = new (A <:< A) {def apply(x: A) = x} |
@dlwh said: (And thanks for considering the change, Scala folks!)
|
(Summary is long and possibly confusing, sorry!)
I've looked over the spec and I can't see why the compiler shouldn't find the type of I in stringer:
The text was updated successfully, but these errors were encountered: