diff options
author | Martin Odersky <odersky@gmail.com> | 2009-10-12 10:57:15 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-10-12 10:57:15 +0000 |
commit | 5d61522281b785ba53c34fe38fe6e1ce59bcfac9 (patch) | |
tree | e0ccda2a8a7fe62ce4a2e2657dac9931d534eaec /test/files | |
parent | bf02e46f2ae1fde75f28da909b8a6e23383cec9b (diff) | |
download | scala-5d61522281b785ba53c34fe38fe6e1ce59bcfac9.tar.gz scala-5d61522281b785ba53c34fe38fe6e1ce59bcfac9.tar.bz2 scala-5d61522281b785ba53c34fe38fe6e1ce59bcfac9.zip |
Fixed #2444
Diffstat (limited to 'test/files')
-rwxr-xr-x | test/files/pos/t1756.scala | 54 | ||||
-rw-r--r-- | test/files/pos/t2444.scala | 15 |
2 files changed, 69 insertions, 0 deletions
diff --git a/test/files/pos/t1756.scala b/test/files/pos/t1756.scala new file mode 100755 index 0000000000..4f7202114c --- /dev/null +++ b/test/files/pos/t1756.scala @@ -0,0 +1,54 @@ + +/** +This is a tricky issue which has to do with the fact that too much conflicting +type information is propagated into a single implicit search, where the intended +solution applies two implicit searches. + +Roughly, in x + x * y, the first x is first typed as Poly[A]. That +means the x * y is then typed as Poly[A]. Then the second x is typed +as Poly[A], then y is typed as Poly[Poly[A]]. The application x * y +fails, so the coef2poly implicit conversion is applied to x. That +means we look for an implicit conversion from type Poly[A] to type +?{val *(x$1: ?>: Poly[Poly[A]] <: Any): Poly[A]}. Note that the result +type Poly[A] is propagated into the implicit search. Poly[A] comes as +expected type from x+, because the lhs x is still typed as a Poly[A]. +This means that the argument of the implicit conversion is typechecked +with expected type A with Poly[A]. And no solution is found. + +To solve this, I added a fallback scheme similar to implicit arguents: +When an implicit view that adds a method matching given arguments and result +type fails, try again without the result type. +*/ +trait Ring[T <: Ring[T]] { + def +(that: T): T + def *(that: T): T +} + +class A extends Ring[A] { + def +(that: A) = new A + def *(that: A) = new A +} + +class Poly[C <: Ring[C]](val c: C) extends Ring[Poly[C]] { + def +(that: Poly[C]) = new Poly(this.c+that.c) + def *(that: Poly[C]) = new Poly(this.c*that.c) +} + +object Test extends Application { + + implicit def coef2poly[C <: Ring[C]](c: C): Poly[C] = new Poly(c) + + val a = new A + val x = new Poly(new A) + + println(x+a) // works + println(a+x) // works + + val y = new Poly(new Poly(new A)) + + println(x+y*x) // works + println(x*y+x) // works + println(y*x+x) // works + + println(x+x*y) // failed before +} diff --git a/test/files/pos/t2444.scala b/test/files/pos/t2444.scala new file mode 100644 index 0000000000..6f07dcf92d --- /dev/null +++ b/test/files/pos/t2444.scala @@ -0,0 +1,15 @@ +object Test { + + trait Foo + + class Bar { + object baz extends Foo + } + + def frob[P1, P2<:Foo](f:P1 => P2) = () + + def main(args:Array[String]) : Unit = { + frob((p:Bar) => p.baz) + } + +} |