diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-06-22 04:24:57 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-06-22 04:24:57 -0700 |
commit | 04e2f86d6b2daf4b53671516659986faca4f82d7 (patch) | |
tree | f8673cf3c1647fa57b1a60e6130fe4c5cf3fe74f /test/files | |
parent | cfc0e18dc55b33274c1275c192ade4a8d707d635 (diff) | |
parent | b29c01b710b67dd329ad418c7d5ef4e61845c6d1 (diff) | |
download | scala-04e2f86d6b2daf4b53671516659986faca4f82d7.tar.gz scala-04e2f86d6b2daf4b53671516659986faca4f82d7.tar.bz2 scala-04e2f86d6b2daf4b53671516659986faca4f82d7.zip |
Merge pull request #755 from axel22/issue/5284-cherry-picked
Fix SI-5284.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/pos/spec-params-new.scala | 2 | ||||
-rw-r--r-- | test/files/run/t5284.check | 1 | ||||
-rw-r--r-- | test/files/run/t5284.scala | 25 | ||||
-rw-r--r-- | test/files/run/t5284b.check | 1 | ||||
-rw-r--r-- | test/files/run/t5284b.scala | 28 | ||||
-rw-r--r-- | test/files/run/t5284c.check | 1 | ||||
-rw-r--r-- | test/files/run/t5284c.scala | 30 |
7 files changed, 87 insertions, 1 deletions
diff --git a/test/files/pos/spec-params-new.scala b/test/files/pos/spec-params-new.scala index 661e686f0e..959ce1591c 100644 --- a/test/files/pos/spec-params-new.scala +++ b/test/files/pos/spec-params-new.scala @@ -31,4 +31,4 @@ class Foo[@specialized A: ClassTag] { val xs = new Array[A](1) xs(0) = x } -}
\ No newline at end of file +} diff --git a/test/files/run/t5284.check b/test/files/run/t5284.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/files/run/t5284.check @@ -0,0 +1 @@ +2 diff --git a/test/files/run/t5284.scala b/test/files/run/t5284.scala new file mode 100644 index 0000000000..ba0845fb8e --- /dev/null +++ b/test/files/run/t5284.scala @@ -0,0 +1,25 @@ + + + + + +/** Here we have a situation where a normalized method parameter `W` + * is used in a position which accepts an instance of type `T` - we know we can + * safely cast `T` to `W` whenever type bounds on `W` hold. + */ +object Test { + def main(args: Array[String]) { + val a = Blarg(Array(1, 2, 3)) + println(a.m((x: Int) => x + 1)) + } +} + + +object Blarg { + def apply[T: Manifest](a: Array[T]) = new Blarg(a) +} + + +class Blarg[@specialized(Int) T: Manifest](val a: Array[T]) { + def m[@specialized(Int) W >: T, @specialized(Int) S](f: W => S) = f(a(0)) +} diff --git a/test/files/run/t5284b.check b/test/files/run/t5284b.check new file mode 100644 index 0000000000..98d9bcb75a --- /dev/null +++ b/test/files/run/t5284b.check @@ -0,0 +1 @@ +17 diff --git a/test/files/run/t5284b.scala b/test/files/run/t5284b.scala new file mode 100644 index 0000000000..a9282a895f --- /dev/null +++ b/test/files/run/t5284b.scala @@ -0,0 +1,28 @@ + + + + + + +/** Here we have a situation where a normalized method parameter `W` + * is used in a position which expects a type `T` - we know we can + * safely cast `W` to `T` whenever typebounds of `W` hold. + */ +object Test { + def main(args: Array[String]) { + val foo = Foo.createUnspecialized[Int] + println(foo.bar(17)) + } +} + + +object Foo { + def createUnspecialized[T] = new Foo[T] +} + + +class Foo[@specialized(Int) T] { + val id: T => T = x => x + + def bar[@specialized(Int) W <: T, @specialized(Int) S](w: W) = id(w) +} diff --git a/test/files/run/t5284c.check b/test/files/run/t5284c.check new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/test/files/run/t5284c.check @@ -0,0 +1 @@ +3 diff --git a/test/files/run/t5284c.scala b/test/files/run/t5284c.scala new file mode 100644 index 0000000000..383b84c2cc --- /dev/null +++ b/test/files/run/t5284c.scala @@ -0,0 +1,30 @@ + + + + + + +/** Here we have a compound type `List[W]` used in + * a position where `List[T]` is expected. The cast + * emitted in the normalized `bar` is safe because the + * normalized `bar` can only be called if the type + * bounds hold. + */ +object Test { + def main(args: Array[String]) { + val foo = Foo.createUnspecialized[Int] + println(foo.bar(List(1, 2, 3))) + } +} + + +object Foo { + def createUnspecialized[T] = new Foo[T] +} + + +class Foo[@specialized(Int) T] { + val len: List[T] => Int = xs => xs.length + + def bar[@specialized(Int) W <: T](ws: List[W]) = len(ws) +} |