From f54e5c8bbdd719b5c9375c64c2f66b841984456e Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sun, 22 Apr 2012 18:49:09 +0200 Subject: resurrects manifests in their pre-2.10 glory --- test/files/pos/contextbounds-implicits-old.scala | 8 ++ test/files/pos/implicits-old.scala | 89 ++++++++++++++++++++++ test/files/pos/manifest1-old.scala | 21 +++++ test/files/pos/nothing_manifest_disambig-old.scala | 10 +++ test/files/pos/spec-constr-old.scala | 7 ++ test/files/pos/spec-doubledef-old.scala | 28 +++++++ test/files/pos/spec-fields-old.scala | 10 +++ test/files/pos/spec-params-old.scala | 32 ++++++++ test/files/pos/spec-sparsearray-old.scala | 24 ++++++ test/files/pos/t1381-old.scala | 31 ++++++++ test/files/pos/t2795-old.scala | 17 +++++ test/files/pos/t3363-old.scala | 18 +++++ test/files/pos/t3498-old.scala | 15 ++++ 13 files changed, 310 insertions(+) create mode 100644 test/files/pos/contextbounds-implicits-old.scala create mode 100644 test/files/pos/implicits-old.scala create mode 100644 test/files/pos/manifest1-old.scala create mode 100644 test/files/pos/nothing_manifest_disambig-old.scala create mode 100644 test/files/pos/spec-constr-old.scala create mode 100644 test/files/pos/spec-doubledef-old.scala create mode 100644 test/files/pos/spec-fields-old.scala create mode 100644 test/files/pos/spec-params-old.scala create mode 100644 test/files/pos/spec-sparsearray-old.scala create mode 100644 test/files/pos/t1381-old.scala create mode 100644 test/files/pos/t2795-old.scala create mode 100644 test/files/pos/t3363-old.scala create mode 100644 test/files/pos/t3498-old.scala (limited to 'test/files/pos') diff --git a/test/files/pos/contextbounds-implicits-old.scala b/test/files/pos/contextbounds-implicits-old.scala new file mode 100644 index 0000000000..f9113ee320 --- /dev/null +++ b/test/files/pos/contextbounds-implicits-old.scala @@ -0,0 +1,8 @@ +/* Tests implicit parameters in the presence of context bounds. + * See Section 7.4 of the Scala Language Specification. + */ +class C { + + def f[T: Manifest, S: Manifest](x: T, y: S)(implicit p: C) { } + +} diff --git a/test/files/pos/implicits-old.scala b/test/files/pos/implicits-old.scala new file mode 100644 index 0000000000..2c01dd0ba8 --- /dev/null +++ b/test/files/pos/implicits-old.scala @@ -0,0 +1,89 @@ +// #1435 +object t1435 { + implicit def a(s:String):String = error("") + implicit def a(i:Int):String = error("") + implicit def b(i:Int):String = error("") +} + +class C1435 { + val v:String = { + import t1435.a + 2 + } +} + +// #1492 +class C1492 { + + class X + + def foo(x: X => X) {} + + foo ( implicit x => implicitly[X] ) + foo { implicit x => implicitly[X] } +} + +// #1579 +object Test1579 { + class Column + class Query[E](val value: E) + class Invoker(q: Any) { val foo = null } + + implicit def unwrap[C](q: Query[C]) = q.value + implicit def invoker(q: Query[Column]) = new Invoker(q) + + val q = new Query(new Column) + q.foo +} +// #1625 +object Test1625 { + + class Wrapped(x:Any) { + def unwrap() = x + } + + implicit def byName[A](x: =>A) = new Wrapped(x) + + implicit def byVal[A](x: A) = x + + def main(args: Array[String]) = { + +// val res:Wrapped = 7 // works + + val res = 7.unwrap() // doesn't work + + println("=> result: " + res) + } +} + +object Test2188 { + implicit def toJavaList[A: ClassManifest](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*) + + val x: java.util.List[String] = List("foo") +} + +object TestNumericWidening { + val y = 1 + val x: java.lang.Long = y +} + +// #2709 +package foo2709 { + class A + class B + + package object bar { + implicit def a2b(a: A): B = new B + } + + package bar { + object test { + new A: B + } + } +} + +// Problem with specs +object specsProblem { + println(implicitly[Manifest[Class[_]]]) +} diff --git a/test/files/pos/manifest1-old.scala b/test/files/pos/manifest1-old.scala new file mode 100644 index 0000000000..8901aa7437 --- /dev/null +++ b/test/files/pos/manifest1-old.scala @@ -0,0 +1,21 @@ +import scala.reflect.Manifest + +object Test { + def foo[T](x: T)(implicit m: Manifest[T]) { + foo(List(x)) + } + foo(1) + foo("abc") + foo(List(1, 2, 3)) + val x: List[Int] with Ordered[List[Int]] = null + foo(x) + foo[x.type](x) + abstract class C { type T = String; val x: T } + val c = new C { val x = "abc" } + foo(c.x) + abstract class D { type T; implicit val m: Manifest[T]; val x: T } + val stringm = implicitly[Manifest[String]] + val d: D = new D { type T = String; val m = stringm; val x = "x" } + import d.m + foo(d.x) +} diff --git a/test/files/pos/nothing_manifest_disambig-old.scala b/test/files/pos/nothing_manifest_disambig-old.scala new file mode 100644 index 0000000000..076742033f --- /dev/null +++ b/test/files/pos/nothing_manifest_disambig-old.scala @@ -0,0 +1,10 @@ +object Test { + def mani[T: Manifest](xs: T) = xs + mani(List()) + + def listElMani[T: Manifest](xs: List[T]) = xs + listElMani(List()) + + def foo[A, C](m : C)(implicit ev: C <:< Traversable[A], mani: Manifest[A]): (C, A, Manifest[A]) = (m, m.head, mani) + foo(List(1,2,3)) +} \ No newline at end of file diff --git a/test/files/pos/spec-constr-old.scala b/test/files/pos/spec-constr-old.scala new file mode 100644 index 0000000000..e908b65a41 --- /dev/null +++ b/test/files/pos/spec-constr-old.scala @@ -0,0 +1,7 @@ +class SparseArray2[@specialized(Int) T:ClassManifest](val maxSize: Int, initialLength:Int = 3) { + private var data = new Array[T](initialLength); + private var index = new Array[Int](initialLength); + + // comment out to compile correctly + data.length + 3; +} diff --git a/test/files/pos/spec-doubledef-old.scala b/test/files/pos/spec-doubledef-old.scala new file mode 100644 index 0000000000..86b0d857d3 --- /dev/null +++ b/test/files/pos/spec-doubledef-old.scala @@ -0,0 +1,28 @@ +object Test { + def fn[@specialized T, @specialized U](t : T => Int, u : U => Int) : T = + null.asInstanceOf[T] +} + +trait A[@specialized(Int) T] { + var value: T + def getWith[@specialized(Int) Z](f: T => Z) = f(value) +} + +class C extends A[Int] { + var value = 10 + override def getWith[@specialized(Int) Z](f: Int => Z) = f(value) +} + +abstract class B[T, @specialized(scala.Int) U : Manifest, @specialized(scala.Int) V <% Ordered[V]] { + val u: U + val v: V + + def f(t: T, v2: V): Pair[U, V] = { + val m: Array[U] = null + if (m.isEmpty) { + Pair(u, v) + } else { + Pair(u, v2) + } + } +} diff --git a/test/files/pos/spec-fields-old.scala b/test/files/pos/spec-fields-old.scala new file mode 100644 index 0000000000..26a8c4ffbd --- /dev/null +++ b/test/files/pos/spec-fields-old.scala @@ -0,0 +1,10 @@ +abstract class Foo[@specialized T: ClassManifest, U <: Ordered[U]](x: T, size: Int) { + var y: T + var z: T = x + + def initialSize = 16 + val array = new Array[T](initialSize + size) + + def getZ = z + def setZ(zz: T) = z = zz +} diff --git a/test/files/pos/spec-params-old.scala b/test/files/pos/spec-params-old.scala new file mode 100644 index 0000000000..f522512846 --- /dev/null +++ b/test/files/pos/spec-params-old.scala @@ -0,0 +1,32 @@ +class Foo[@specialized A: ClassManifest] { + + // conflicting in bounds, expect a normalized member calling m + // and bridge + implementation in specialized subclasses + // and overloads here according to specialization on A + def m1[@specialized B <: A](x: B, y: A) = + goal(x) + + // conflicting, unsolvable, expect a warning + def m2[@specialized B <: String](x: B) = x.concat("a") + + // conflicting in bounds, no mention of other spec members + // expect an overload here plus implementation in + // compatible specialized subclasses + def m3[@specialized B >: A](x: B) = () + + // non-conflicting, expect a normalized overload implementation here + def m4[@specialized T, U <: Ordered[T]](x: T, y: U) = () + + // non-conflicting, expect a normalized overload implementation here + def m5[@specialized B](x: B) = x + + // non-conflicting, expect a normalized implementation here + // and specialized implementations for all expansions in specialized subclasses + def m6[@specialized B](x: B, y: A) = + goal(y) + + def goal(x: A) = { + val xs = new Array[A](1) + xs(0) = x + } +} diff --git a/test/files/pos/spec-sparsearray-old.scala b/test/files/pos/spec-sparsearray-old.scala new file mode 100644 index 0000000000..ea7710a785 --- /dev/null +++ b/test/files/pos/spec-sparsearray-old.scala @@ -0,0 +1,24 @@ +import scala.collection.mutable.MapLike + +class SparseArray[@specialized(Int) T:ClassManifest] extends collection.mutable.Map[Int,T] with collection.mutable.MapLike[Int,T,SparseArray[T]] { + override def get(x: Int) = { + val ind = findOffset(x) + if(ind < 0) None else Some(error("ignore")) + } + + /** + * Returns the offset into index and data for the requested vector + * index. If the requested index is not found, the return value is + * negative and can be converted into an insertion point with -(rv+1). + */ + private def findOffset(i : Int) : Int = { + error("impl doesn't matter") + } + + override def apply(i : Int) : T = { error("ignore") } + override def update(i : Int, value : T) = error("ignore") + override def empty = new SparseArray[T] + def -=(ind: Int) = error("ignore") + def +=(kv: (Int,T)) = error("ignore") + override final def iterator = error("ignore") +} diff --git a/test/files/pos/t1381-old.scala b/test/files/pos/t1381-old.scala new file mode 100644 index 0000000000..0762891898 --- /dev/null +++ b/test/files/pos/t1381-old.scala @@ -0,0 +1,31 @@ +import scala.reflect.Manifest + +class D[V <: Variable] + +class ID[V<:IV] extends D[V] { + type E = V#ValueType + def index(value:E) : Int = 0 + // Comment this out to eliminate crash. Or see below + def index(values:E*) : Iterable[Int] = null +} + +abstract class Variable { + type VT <: Variable + def d : D[VT] = null +} + +abstract class PV[T](initval:T) extends Variable { + type VT <: PV[T] + type ValueType = T +} + +trait IV extends Variable { + type ValueType +} + +abstract class EV[T](initval:T) extends PV[T](initval) with IV { + type VT <: EV[T] + override def d : ID[VT] = null + // Comment this out to eliminate crash + protected var indx = d.index(initval) +} diff --git a/test/files/pos/t2795-old.scala b/test/files/pos/t2795-old.scala new file mode 100644 index 0000000000..935cb1f444 --- /dev/null +++ b/test/files/pos/t2795-old.scala @@ -0,0 +1,17 @@ +package t1 + +trait Element[T] { +} + +trait Config { + type T <: Element[T] + implicit val m: ClassManifest[T] + // XXX Following works fine: + // type T <: Element[_] +} + +trait Transform { self: Config => + def processBlock(block: Array[T]): Unit = { + var X = new Array[T](1) + } +} diff --git a/test/files/pos/t3363-old.scala b/test/files/pos/t3363-old.scala new file mode 100644 index 0000000000..bae54084ea --- /dev/null +++ b/test/files/pos/t3363-old.scala @@ -0,0 +1,18 @@ +object TestCase { + + //now matter if you put (abstract) class or trait it will fail in all cases + trait MapOps[T] + + //if fs was reduced to List (generic type with one parameter) then the code compiles + //if you inherit from MapOps[T] instead of MapOps[F] then code compiles fine + implicit def map2ops[T,F](fs: Map[T,F]) = new MapOps[F] { + //if you remove this line, then code compiles + lazy val m: Manifest[T] = error("just something to make it compile") + def is(xs: List[T]) = List(xs) + } + + def main(args: Array[String]) { + println(Map(1 -> "2") is List(2)) + } + + } diff --git a/test/files/pos/t3498-old.scala b/test/files/pos/t3498-old.scala new file mode 100644 index 0000000000..bcc90ca64c --- /dev/null +++ b/test/files/pos/t3498-old.scala @@ -0,0 +1,15 @@ +abstract class A[T, @specialized(scala.Int) U : Manifest] { + def f(state: T): Array[U] +} + +abstract class B extends A[ Array[Byte], Int ] { + type T = Array[Byte] + type U = Int + + val N = 0 + + def f(state: T): Array[U] = + { + new Array[U](N + state(N)) + } +} \ No newline at end of file -- cgit v1.2.3