diff options
author | Martin Odersky <odersky@gmail.com> | 2014-05-05 18:34:59 +0200 |
---|---|---|
committer | Samuel Gruetter <samuel.gruetter@epfl.ch> | 2014-05-20 13:38:48 +0200 |
commit | 82c4db686d07ae8e91f157f5c8b55a1a76917941 (patch) | |
tree | 3024867516bdc571987207296046fe5bcd3ca566 /tests/pending/pos | |
parent | 94ceb9895a539b05fd81c8abe040c276178b5507 (diff) | |
download | dotty-82c4db686d07ae8e91f157f5c8b55a1a76917941.tar.gz dotty-82c4db686d07ae8e91f157f5c8b55a1a76917941.tar.bz2 dotty-82c4db686d07ae8e91f157f5c8b55a1a76917941.zip |
Pos tests t17xx - t19xx
Diffstat (limited to 'tests/pending/pos')
-rwxr-xr-x | tests/pending/pos/t1756.scala | 54 | ||||
-rw-r--r-- | tests/pending/pos/t1832.scala | 10 |
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/pending/pos/t1756.scala b/tests/pending/pos/t1756.scala new file mode 100755 index 000000000..1d067c3b0 --- /dev/null +++ b/tests/pending/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 arguments: +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 App { + + 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/tests/pending/pos/t1832.scala b/tests/pending/pos/t1832.scala new file mode 100644 index 000000000..9ad9703c2 --- /dev/null +++ b/tests/pending/pos/t1832.scala @@ -0,0 +1,10 @@ +trait Cloning { + trait Foo + def fn(g: Any => Unit): Foo + + class Star { def *(a: Cloning.this.Foo): Cloning.this.Foo } + + implicit def mkStar(i: Int): Star = new Star { def *(a: Foo): Foo = null } + + val pool = 4 * fn { case ghostSYMBOL: Int => ghostSYMBOL * 2 } +} |