diff options
author | Aleksandar Prokopec <axel22@gmail.com> | 2012-05-07 15:39:53 +0200 |
---|---|---|
committer | Aleksandar Prokopec <axel22@gmail.com> | 2012-05-07 15:39:53 +0200 |
commit | a11a57735e73d66147f9f6166687ad7bc04feca8 (patch) | |
tree | 3b24a3ac25ab7ecc8e72c27f86c9a7783adb3c0a /test/files/run/t5629b.scala | |
parent | ea25648d2737e6110b6a643b0ac4e852688a3cab (diff) | |
download | scala-a11a57735e73d66147f9f6166687ad7bc04feca8.tar.gz scala-a11a57735e73d66147f9f6166687ad7bc04feca8.tar.bz2 scala-a11a57735e73d66147f9f6166687ad7bc04feca8.zip |
Fixes SI-5629.
Adds an additional argument to the unify method in
specialization - `tparams`. When this parameter is set
to `true`, unification is done over type parameters in
poly types as well.
Additionally, the unification in specialization now
works over type bounds.
This ensures that in the below example:
trait Foo[@specialized(Int) A] {
def bar[B <: A](b: B) {}
}
class IntFoo extends Foo[Int] {
override def bar[B <: Int](b: B) {}
}
the method `bar` gets correctly determined
as a method that needs a special override
for its `bar$mcI$sp`.
Diffstat (limited to 'test/files/run/t5629b.scala')
-rw-r--r-- | test/files/run/t5629b.scala | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/files/run/t5629b.scala b/test/files/run/t5629b.scala new file mode 100644 index 0000000000..6c908081b9 --- /dev/null +++ b/test/files/run/t5629b.scala @@ -0,0 +1,41 @@ + + + + + +object Test extends App { + + trait MyPF[@specialized(Int) -A] extends (A => Unit) { + def isDefinedAt(x: A): Boolean + def applyOrElse[A1 <: A](x: A1, default: A1 => Unit): Unit = { + println("MyPF.applyOrElse entered...") + if (isDefinedAt(x)) apply(x) else default(x) + } + } + + trait MySmartPF[@specialized(Int) -A] extends MyPF[A] { + def apply(x: A): Unit = { + println("MySmartPF.apply entered...") + applyOrElse(x, { _: Any => throw new MatchError }) + } + } + + type T = Int + //type T = Any + + def newPF(test: T): MyPF[T] = new MySmartPF[T] { + def isDefinedAt(x: T): Boolean = x != test + override def applyOrElse[A1 <: T](x: A1, default: A1 => Unit): Unit = { + println("newPF.applyOrElse entered...") + if (x != test) { println("ok"); () } else { println("default"); default(x) } + } + } + + val pf = newPF(1) + println("=== pf(1):") + try { pf(1) } catch { case x => println(x) } + println("=== pf(42):") + pf(42) + println("=== done") + +} |