diff options
Diffstat (limited to 'tests/pos')
116 files changed, 1929 insertions, 17 deletions
diff --git a/tests/pos/conforms.scala b/tests/pos/conforms.scala new file mode 100644 index 000000000..f07488d28 --- /dev/null +++ b/tests/pos/conforms.scala @@ -0,0 +1,3 @@ +object Test { + def f[A, B](x: A)(implicit e: <:<[A, B]): B = x +} diff --git a/tests/pos/constfold.scala b/tests/pos/constfold.scala new file mode 100644 index 000000000..8d431efba --- /dev/null +++ b/tests/pos/constfold.scala @@ -0,0 +1,14 @@ +object A { + val x = 2; + val y = x.asInstanceOf[Byte]; + val z = 1.0 / 2; + val s = "z is " + z; +} + +object Test extends App { + + Console.println(A.x); + Console.println(A.y); + Console.println(A.z); + Console.println(A.s); +} diff --git a/tests/pos/contextbounds-implicits-new.scala b/tests/pos/contextbounds-implicits-new.scala new file mode 100644 index 000000000..8389d1332 --- /dev/null +++ b/tests/pos/contextbounds-implicits-new.scala @@ -0,0 +1,10 @@ +import scala.reflect.runtime.universe._ + +/* Tests implicit parameters in the presence of context bounds. + * See Section 7.4 of the Scala Language Specification. + */ +class C { + + def f[T: TypeTag, S: TypeTag](x: T, y: S)(implicit p: C): Unit = { } + +} diff --git a/tests/pos/delambdafy-lambdalift.scala b/tests/pos/delambdafy-lambdalift.scala new file mode 100644 index 000000000..e9da24ef3 --- /dev/null +++ b/tests/pos/delambdafy-lambdalift.scala @@ -0,0 +1,8 @@ +class LambdaLift { + + def enclosingMethod(capturedArg: Int): Unit = { + def innerMethod(x: Int): Int = x + capturedArg + val f = (y: Int) => innerMethod(y) + } + +} diff --git a/tests/pos/exbound.scala b/tests/pos/exbound.scala new file mode 100644 index 000000000..be78abc26 --- /dev/null +++ b/tests/pos/exbound.scala @@ -0,0 +1,7 @@ +class A[T <: A[T]] { + +} + +object Test { + val x: A[_] = null +} diff --git a/tests/pos/hkrange.scala b/tests/pos/hkrange.scala deleted file mode 100644 index a6803230e..000000000 --- a/tests/pos/hkrange.scala +++ /dev/null @@ -1,5 +0,0 @@ -class A { - def f[CC[X] <: Traversable[X]](x: CC[Int]) = () - - f(1 to 5) -} diff --git a/tests/pos/implicits.scala b/tests/pos/implicits.scala new file mode 100644 index 000000000..1a3e0b4da --- /dev/null +++ b/tests/pos/implicits.scala @@ -0,0 +1,9 @@ +object Test { + + class X(i: Int) + + implicit def int2x(i: Int): X = new X(i) + + val x: X = Byte.MinValue + +} diff --git a/tests/pos/philippe4.scala b/tests/pos/philippe4.scala new file mode 100644 index 000000000..9ce3691f5 --- /dev/null +++ b/tests/pos/philippe4.scala @@ -0,0 +1,3 @@ +trait Foo[t <: Foo[t]] { self: t => + def foo(that: t): Boolean; +} diff --git a/tests/pos/seq-ordering.scala b/tests/pos/seq-ordering.scala deleted file mode 100644 index 517d8ae8a..000000000 --- a/tests/pos/seq-ordering.scala +++ /dev/null @@ -1,9 +0,0 @@ -import Ordering.Implicits._ - -class A { - import Predef.{ implicitly => ? } - - ?[Ordering[List[Int]]] - ?[Ordering[IndexedSeq[(Int, String)]]] - ?[Ordering[Seq[Seq[Int]]]] -} diff --git a/tests/pos/t1048.scala b/tests/pos/t1048.scala new file mode 100644 index 000000000..b8694b38e --- /dev/null +++ b/tests/pos/t1048.scala @@ -0,0 +1,14 @@ +trait T[U] { + def x: T[_ <: U] +} + +object T { + def unapply[U](t: T[U]): Option[T[_ <: U]] = Some(t.x) +} + +object Test { + def f[W](t: T[W]) = t match { + case T(T(_)) => () + } +} + diff --git a/tests/pos/t1843.scala b/tests/pos/t1843.scala index 5e8554a93..871b21346 100644 --- a/tests/pos/t1843.scala +++ b/tests/pos/t1843.scala @@ -3,10 +3,9 @@ * ... Or Will It? * */ - object Crash { - trait UpdateType[+A] - case class StateUpdate[+A](updateType : UpdateType[A], value : A) + trait UpdateType[A] + case class StateUpdate[A](updateType : UpdateType[A], value : A) case object IntegerUpdateType extends UpdateType[Integer] //However this method will cause a crash diff --git a/tests/pos/t3274.scala b/tests/pos/t3274.scala new file mode 100644 index 000000000..bd8b080c9 --- /dev/null +++ b/tests/pos/t3274.scala @@ -0,0 +1,9 @@ +trait A { this: B => + trait X { + class Y1 extends Y + } +} + +trait B extends A { + trait Y { def f: Unit = {} } +} diff --git a/tests/pos/t3477.scala b/tests/pos/t3477.scala new file mode 100644 index 000000000..6a94baa6c --- /dev/null +++ b/tests/pos/t3477.scala @@ -0,0 +1,7 @@ +class J3 { + def f[K, K1 >: K, V](x: Map[K1, V]): Map[K, V] = sys.error("") +} + +object Test { + (new J3).f(Map[Int, Int]()) +} diff --git a/tests/pos/t3480.scala b/tests/pos/t3480.scala new file mode 100644 index 000000000..ba2e1a4b8 --- /dev/null +++ b/tests/pos/t3480.scala @@ -0,0 +1,4 @@ +object Test { + val List(_: _*) = List(1) + val Array( who, what : _* ) = "Eclipse plugin cannot not handle this" split (" ") +} diff --git a/tests/pos/t3498-new.scala b/tests/pos/t3498-new.scala new file mode 100644 index 000000000..ccf2af9de --- /dev/null +++ b/tests/pos/t3498-new.scala @@ -0,0 +1,17 @@ +import scala.reflect.{ClassTag, classTag} + +abstract class A[T, @specialized(scala.Int) U : ClassTag] { + 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)) + } +} diff --git a/tests/pos/t3534.scala b/tests/pos/t3534.scala new file mode 100644 index 000000000..44d3aafb6 --- /dev/null +++ b/tests/pos/t3534.scala @@ -0,0 +1,6 @@ +object Test { + List[Option[Int]]() match { + case None :: bb :: cc => () + case x => throw new Exception(x.filter(_.isDefined).mkString) + } + } diff --git a/tests/pos/t3568.scala b/tests/pos/t3568.scala new file mode 100644 index 000000000..50f0cdb2e --- /dev/null +++ b/tests/pos/t3568.scala @@ -0,0 +1,46 @@ +import scala.annotation._ +import scala.annotation.unchecked._ +import scala.collection._ + + +package object buffer { + val broken = new ArrayVec2() // commenting out this line causes the file to compile. + + val works = Class.forName("buffer.ArrayVec2").newInstance().asInstanceOf[ArrayVec2] +} + +package buffer { + object Main { + // ArrayVec2 can be compiled, instantiated and used. + def main(args: Array[String]): Unit = { println(works) } + } + + trait ElemType { type Element; type Component <: ElemType } + trait Float1 extends ElemType { type Element = Float; type Component = Float1} + class Vec2 extends ElemType { type Element = Vec2; type Component = Float1 } + + abstract class BaseSeq[T <: ElemType, E] + extends IndexedSeq[E] with IndexedSeqOptimized[E, IndexedSeq[E]] { + def length = 1 + def apply(i: Int) :E + } + + abstract class GenericSeq[T <: ElemType] extends BaseSeq[T, T#Element] + trait DataArray[T <: ElemType] extends BaseSeq[T, T#Element] + trait DataView[T <: ElemType] extends BaseSeq[T, T#Element] + abstract class BaseFloat1 extends BaseSeq[Float1, Float] + + class ArrayFloat1 extends BaseFloat1 with DataArray[Float1] { + def apply(i: Int) :Float = 0f + } + + class ViewFloat1 extends BaseFloat1 with DataView[Float1] { + def apply(i: Int) :Float = 0f + } + + class ArrayVec2(val backingSeq: ArrayFloat1) + extends GenericSeq[Vec2] with DataArray[Vec2] { + def this() = this(new ArrayFloat1) + def apply(i: Int) :Vec2 = null + } +} diff --git a/tests/pos/t3582b.scala b/tests/pos/t3582b.scala new file mode 100644 index 000000000..f7778148e --- /dev/null +++ b/tests/pos/t3582b.scala @@ -0,0 +1,5 @@ +object ParamScoping { + // scoping worked fine in the result type, but was wrong in body + // reason: typedTypeDef needs new context, which was set up by typed1 but not by typedDefDef and typedClassDef + def noOverlapFOwithHO[T, G[T]]: G[T] = null.asInstanceOf[G[T]] +} diff --git a/tests/pos/t360.scala b/tests/pos/t360.scala new file mode 100644 index 000000000..f3716d4f9 --- /dev/null +++ b/tests/pos/t360.scala @@ -0,0 +1,9 @@ +abstract class Bug360A { self: Bug360C => + def f: String = "hello"; +} +trait Bug360B { self: Bug360C => + object d { + Console.println(f); + } +} +abstract class Bug360C extends Bug360A with Bug360B; diff --git a/tests/pos/t3612.scala b/tests/pos/t3612.scala new file mode 100644 index 000000000..a9d063998 --- /dev/null +++ b/tests/pos/t3612.scala @@ -0,0 +1,6 @@ +trait C + +class Outer { + object O0 extends C {} + object O extends C { self => } +} diff --git a/tests/pos/t3688.scala b/tests/pos/t3688.scala new file mode 100644 index 000000000..bf7983081 --- /dev/null +++ b/tests/pos/t3688.scala @@ -0,0 +1,14 @@ +import collection.mutable +import collection.JavaConversions._ +import java.{util => ju} + +object Test { + + implicitly[mutable.Map[Int, String] => ju.Dictionary[Int, String]] + +} + +object Test2 { + def m[P <% ju.List[Int]](l: P) = 1 + m(List(1)) // bug: should compile +} diff --git a/tests/pos/t3777.scala b/tests/pos/t3777.scala new file mode 100644 index 000000000..165eeebfd --- /dev/null +++ b/tests/pos/t3777.scala @@ -0,0 +1,7 @@ +object Test { + type Point = Map[Symbol, String] + type Points = IndexedSeq[Point] + + def makePoints2: Points = IndexedSeq[Point]() + val spoints2 = util.Random.shuffle(makePoints2) +} diff --git a/tests/pos/t3859.scala b/tests/pos/t3859.scala new file mode 100644 index 000000000..992207301 --- /dev/null +++ b/tests/pos/t3859.scala @@ -0,0 +1,4 @@ +class Test { + def foo: Unit = bar(Array(): _*) + def bar(values: AnyRef*): Unit = () +} diff --git a/tests/pos/t3869.scala b/tests/pos/t3869.scala new file mode 100644 index 000000000..581c11c81 --- /dev/null +++ b/tests/pos/t3869.scala @@ -0,0 +1,10 @@ + +// see ticket #3869 +object Test { + def f: Unit = + try return finally while(true) () + + def main(args: Array[String]): Unit = { + f + } +} diff --git a/tests/pos/t3960.scala b/tests/pos/t3960.scala new file mode 100644 index 000000000..5c658e9fb --- /dev/null +++ b/tests/pos/t3960.scala @@ -0,0 +1,7 @@ +class A { + class C[x] + val cs = new scala.collection.mutable.HashMap[C[_], Int] + def c: C[_] = sys.error("") + val eval: C[_] = c + cs(c) += 1 +} diff --git a/tests/pos/t3986.scala b/tests/pos/t3986.scala new file mode 100644 index 000000000..ea6c64fde --- /dev/null +++ b/tests/pos/t3986.scala @@ -0,0 +1,10 @@ +object Test { + def main(args: Array[String]): Unit = { + new AnyRef { +// TODO NEEDS MANUAL CHANGE (early initializers) +// BEGIN copied early initializers +val x = "abc" +// END copied early initializers + } + } +} diff --git a/tests/pos/t404.scala b/tests/pos/t404.scala new file mode 100644 index 000000000..8f5e8bef5 --- /dev/null +++ b/tests/pos/t404.scala @@ -0,0 +1,12 @@ +trait AbsIterator { + type T + def next: T +} +class StringIterator extends AbsIterator { + type T = Char + def next = 'a' +} +trait SyncIterator extends AbsIterator { + abstract override def next: T = super.next +} +class I extends StringIterator with SyncIterator diff --git a/tests/pos/t415.scala b/tests/pos/t415.scala new file mode 100644 index 000000000..355b6136d --- /dev/null +++ b/tests/pos/t415.scala @@ -0,0 +1,9 @@ +abstract class A { + type T <: String; + def x: T; +} + +abstract class B { + def a: A; + val y: String = a.x; +} diff --git a/tests/pos/t4176.scala b/tests/pos/t4176.scala new file mode 100644 index 000000000..b4f1e705b --- /dev/null +++ b/tests/pos/t4176.scala @@ -0,0 +1,6 @@ +// a.scala +// Fri Jan 20 12:22:51 PST 2012 + +class A(xs: Int*) { def getXs = xs } + +class B extends A { override def getXs = Nil } diff --git a/tests/pos/t430-feb09.scala b/tests/pos/t430-feb09.scala new file mode 100644 index 000000000..1499f32b7 --- /dev/null +++ b/tests/pos/t430-feb09.scala @@ -0,0 +1,34 @@ +// Compiles +package a { + case class A[T]() +} + +// Compiles +package b.scala { + class B[T] +} + +// Doesn't compile: type Nothing is not a member of c.scala +package c.scala { + case class C[T]() +} + +// Doesn't compile: type Nothing is not a member of d.scala +package d.scala.d { + case class D[T]() +} + +// Doesn't compile: type Any is not a member of e.scala +package e.scala { + case class E[T >: Nothing]() +} + +// Compiles +package f.scala { + case class F[T >: Nothing <: Any]() +} + +// Doesn't compile: type <byname> is not a member of package h.scala +package h.scala { + case class H(s: String)(t: =>String) +} diff --git a/tests/pos/t4336.scala b/tests/pos/t4336.scala new file mode 100644 index 000000000..e10d00158 --- /dev/null +++ b/tests/pos/t4336.scala @@ -0,0 +1,19 @@ +object Main { + class NonGeneric {} + class Generic[T] {} + + class Composite { + def contains(setup : Composite => Unit) : Composite = this + } + + def generic[T](parent: Composite): Generic[T] = new Generic[T] + def nonGeneric(parent: Composite): NonGeneric = new NonGeneric + + new Composite().contains( + nonGeneric // should have type Composite => NonGeneric + ) + + new Composite().contains( + generic[Int] // should have type Composite => Generic[Int] + ) +} diff --git a/tests/pos/t4345.scala b/tests/pos/t4345.scala new file mode 100644 index 000000000..b0131d5fa --- /dev/null +++ b/tests/pos/t4345.scala @@ -0,0 +1,7 @@ +trait C1[+A, +CC[X]] { + protected[this] def f: A => CC[A] = sys.error("") +} + +trait C2[+A, +CC[X]] extends C1[A, CC] { + override protected[this] def f = super.f +} diff --git a/tests/pos/t4545.scala b/tests/pos/t4545.scala new file mode 100644 index 000000000..b2b67fa8f --- /dev/null +++ b/tests/pos/t4545.scala @@ -0,0 +1,14 @@ +object Test { + def f[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T](table: Tuple20[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T])(fun: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T) => Unit): Unit = { + } + def g[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U](table: Tuple21[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U])(fun: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U) => Unit): Unit = { + } + + def g20 = f( + ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) + ) { case ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)) => () } + + def g21 = g( + (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) + ) { case ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u)) => () } +} diff --git a/tests/pos/t460.scala b/tests/pos/t460.scala new file mode 100644 index 000000000..3fc13e4dd --- /dev/null +++ b/tests/pos/t460.scala @@ -0,0 +1,9 @@ +object Bug460 { + def testFun(x : Int, y : Int) = x + y + val fn = testFun _ + + fn(1, 2) // Ok + (testFun(_, _))(1, 2) // Ok + (testFun _).apply(1, 2) + (testFun _)(1, 2) // Error! (but no longer) +} diff --git a/tests/pos/t4853.scala b/tests/pos/t4853.scala new file mode 100644 index 000000000..f227ef36e --- /dev/null +++ b/tests/pos/t4853.scala @@ -0,0 +1,12 @@ +object Animal { + def main(args: Array[String]): Unit = { new Animal[Awake].goToSleep } +} + +class Animal[A <: AwakeOrAsleep] { + def goToSleep[B >: A <: Awake]: Animal[Asleep] = new Animal[Asleep] + def wakeUp[B >: A <: Asleep]: Animal[Awake] = new Animal[Awake] +} + +sealed trait AwakeOrAsleep +trait Awake extends AwakeOrAsleep +trait Asleep extends AwakeOrAsleep diff --git a/tests/pos/t4859.scala b/tests/pos/t4859.scala new file mode 100644 index 000000000..284a39b7a --- /dev/null +++ b/tests/pos/t4859.scala @@ -0,0 +1,17 @@ +object O { + // error: C is not a legal prefix for a constructor + C().CC() + // but this works. + D().DD() +} + +case class C() { + case class CC() +} + +case class D() { + class DD() + object DD { + def apply() = new DD() + } +} diff --git a/tests/pos/t4911.flags b/tests/pos/t4911.flags new file mode 100644 index 000000000..a5c112f5a --- /dev/null +++ b/tests/pos/t4911.flags @@ -0,0 +1 @@ +-language:Scala2
\ No newline at end of file diff --git a/tests/pos/t4911.scala b/tests/pos/t4911.scala new file mode 100644 index 000000000..cfb3792ae --- /dev/null +++ b/tests/pos/t4911.scala @@ -0,0 +1,16 @@ +import language._ + +object Test { + class Foo[T](val x: T) ; object Foo { def unapply[T](x: Foo[T]) = Some(x.x) } + def f1[T](x: Foo[T]) = x match { case Foo(y) => y } + def f2[M[_], T](x: M[T]) = x match { case Foo(y) => y } + + case class Bar[T](x: T) + def f3[T](x: Bar[T]) = x match { case Bar(y) => y } + def f4[M[_], T](x: M[T]) = x match { case Bar(y) => y } +} +// +// ./b.scala:4: warning: non variable type-argument T in type pattern Test.Foo[T] is unchecked since it is eliminated by erasure +// def f2[M[_], T](x: M[T]) = x match { case Foo(y) => y } +// ^ +// one warning found diff --git a/tests/pos/t4975.scala b/tests/pos/t4975.scala new file mode 100644 index 000000000..3339631dc --- /dev/null +++ b/tests/pos/t4975.scala @@ -0,0 +1,12 @@ +object ImplicitScope { + class A[T] + + def foo: Unit = { + trait B + object B { + implicit def ab: ImplicitScope.A[B] = new A[B] + } + + implicitly[A[B]] // Error + } +} diff --git a/tests/pos/t5012.scala b/tests/pos/t5012.scala new file mode 100644 index 000000000..84404495c --- /dev/null +++ b/tests/pos/t5012.scala @@ -0,0 +1,12 @@ +class D { + object p // (program point 1) +} + +class C { + def m: D = { + if ("abc".length == 0) { + object p // (program point 2) + } + null + } +} diff --git a/tests/pos/t5029.scala b/tests/pos/t5029.scala new file mode 100644 index 000000000..f32d0c650 --- /dev/null +++ b/tests/pos/t5029.scala @@ -0,0 +1,3 @@ +object Test { + (Vector(): Seq[_]) match { case List() => true; case Nil => false } +} diff --git a/tests/pos/t5041.scala b/tests/pos/t5041.scala new file mode 100644 index 000000000..78a1b27d5 --- /dev/null +++ b/tests/pos/t5041.scala @@ -0,0 +1,9 @@ +case class Token(text: String, startIndex: Int) + +object Comment { + def unapply(s: String): Option[Token] = None +} + +object HiddenTokens { + "foo" match { case Comment(_) => } +} diff --git a/tests/pos/t5082.scala b/tests/pos/t5082.scala new file mode 100644 index 000000000..63eeda38b --- /dev/null +++ b/tests/pos/t5082.scala @@ -0,0 +1,14 @@ +trait Something[T] +object Test { class A } +case class Test() extends Something[Test.A] + +object User { + val Test() = Test() +} + +object Wrap { + trait Something[T] + object Test { class A } + case class Test(a: Int, b: Int)(c: String) extends Something[Test.A] + val Test(x, y) = Test(1, 2)(""); (x + y).toString +} diff --git a/tests/pos/t5541.scala b/tests/pos/t5541.scala new file mode 100644 index 000000000..54e2b6518 --- /dev/null +++ b/tests/pos/t5541.scala @@ -0,0 +1,61 @@ +package philips.adolf.paul + +trait Sys[ S <: Sys[ S ]] { + type Tx +} + +object HASkipList { + sealed trait NodeLike[ S <: Sys[ S ], @specialized( Int ) A ] { + def size : Int + def key( i: Int ): A + } + sealed trait Node[ S <: Sys[ S ], @specialized( Int ) A ] extends NodeLike[ S, A ] { + def isLeaf : Boolean + def isBranch : Boolean + def asBranch : Branch[ S, A ] + } + sealed trait BranchLike[ S <: Sys[ S ], @specialized( Int ) A ] extends NodeLike[ S, A ] { + def down( i: Int )( implicit tx: S#Tx ) : Node[ S, A ] = sys.error("") + } + sealed trait HeadOrBranch[ S <: Sys[ S ], A ] + final class Branch[ S <: Sys[ S ], @specialized( Int ) A ]() + extends BranchLike[ S, A ] with HeadOrBranch[ S, A ] with Node[ S, A ] { + def size:Int=1234 + def key(i: Int):A=sys.error("TODO") + def isLeaf : Boolean = false + def isBranch : Boolean = true + def asBranch : Branch[ S, A ] = this + } +} +sealed trait HASkipList[ S <: Sys[ S ], @specialized( Int ) A ] + +class HASkipListView[ S <: Sys[ S ], A ]( private val l: HASkipList[ S, A ])( implicit system: S ) { + import HASkipList.Node + private def buildBoxMap( n: Node[ S, A ], isRight: Boolean )( implicit tx: S#Tx ) : (Box, NodeBox) = { + val sz = n.size + val szm = sz - 1 + val keys = IndexedSeq.tabulate( sz ) { i => + val key = n.key( i ) + (key, if ( isRight && i == szm ) "M" else key.toString) + } + val chbo = if ( n.isLeaf ) None else { + val nb = n.asBranch + Some( IndexedSeq.tabulate( sz )( i => buildBoxMap( nb.down( i ), isRight && (i == szm) ))) + } + val b = NodeBox( n, keys, chbo.map( _.map( _._2 ))) + val bb = chbo match { + case Some( chbt ) => + val chb = chbt.map( _._1 ) + val h = Horiz( bs = chb ) + Vert( bs = IndexedSeq[Box]( b, h )) + case None => b + } + + (bb, b) + } + + private trait Box + private case class Horiz( spacing: Int = 20, bs: IndexedSeq[ Box ]) extends Box + private final case class Vert( spacing: Int = 20, bs: IndexedSeq[ Box ]) extends Box + private final case class NodeBox( n: Node[ S, A ], keys: IndexedSeq[ (A, String) ], downs: Option[ IndexedSeq[ NodeBox ]]) extends Box +} diff --git a/tests/pos/t566.scala b/tests/pos/t566.scala new file mode 100644 index 000000000..6a2a0a362 --- /dev/null +++ b/tests/pos/t566.scala @@ -0,0 +1,4 @@ +object test { + def foo[a](ys: List[a]): List[a] = + return ys.head :: ys.tail +} diff --git a/tests/pos/t5720-ownerous.scala b/tests/pos/t5720-ownerous.scala new file mode 100644 index 000000000..e171ce9c2 --- /dev/null +++ b/tests/pos/t5720-ownerous.scala @@ -0,0 +1,56 @@ + +/* + * The block under qual$1 must be owned by it. + * In the sample bug, the first default arg generates x$4, + * the second default arg generates qual$1, hence the maximal + * minimization. + * + <method> <triedcooking> def model: C.this.M = { + val qual$1: C.this.M = scala.Option.apply[C.this.M]({ + val x$1: lang.this.String("foo") = "foo"; + val x$2: String = C.this.M.apply$default$2("foo"); + C.this.M.apply("foo")(x$2) +}).getOrElse[C.this.M]({ + val x$3: lang.this.String("bar") = "bar"; + val x$4: String = C.this.M.apply$default$2("bar"); + C.this.M.apply("bar")(x$4) + }); + val x$5: lang.this.String("baz") = "baz"; + val x$6: String = qual$1.copy$default$2("baz"); + qual$1.copy("baz")(x$6) + } + */ +class C { + case class M(currentUser: String = "anon")(val message: String = "empty") + val m = M("foo")() + + // reported + //def model = Option(M("foo")()).getOrElse(M("bar")()).copy(currentUser = "")() + + // the bug + def model = Option(m).getOrElse(M("bar")()).copy("baz")("empty") + + // style points for this version + def modish = ((null: Option[M]) getOrElse new M()()).copy()("empty") + + // various simplifications are too simple + case class N(currentUser: String = "anon") + val n = N("fun") + def nudel = Option(n).getOrElse(N()).copy() +} + +object Test { + def main(args: Array[String]): Unit = { + val c = new C + println(c.model.currentUser) + println(c.model.message) + } +} +/* +symbol value x$4$1 does not exist in badcopy.C.model +at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:45) +at scala.tools.nsc.Global.abort(Global.scala:202) +at scala.tools.nsc.backend.icode.GenICode$ICodePhase.liftedTree2$1(GenICode.scala:998) +at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:992) +*/ + diff --git a/tests/pos/t5729.scala b/tests/pos/t5729.scala new file mode 100644 index 000000000..944aa04d8 --- /dev/null +++ b/tests/pos/t5729.scala @@ -0,0 +1,6 @@ +trait T[X] +object Test { + def join(in: Seq[T[_]]): Int = ??? + def join[S](in: Seq[T[S]]): String = ??? + join(null: Seq[T[_]]) +} diff --git a/tests/pos/t573.scala b/tests/pos/t573.scala new file mode 100644 index 000000000..1aadb446c --- /dev/null +++ b/tests/pos/t573.scala @@ -0,0 +1,43 @@ +package lampion.collections; + +object DirX { + abstract class Dir { + def reverse : Dir; + } + object BEFORE extends Dir { + def reverse = AFTER; + } + object AFTER extends Dir { + def reverse = BEFORE; + } +} + +import DirX._; + +abstract class Linked { + type Node <: Node0; + + abstract class Node0 { + self: Node => + + var next : Node = _; + var prev : Node = _; + + def get(dir : Dir) = if (dir == BEFORE) prev; else next; + private def set(dir : Dir, node : Node) = + if (dir == BEFORE) prev = node; else next = node; + + def link(dir : Dir, node : Node) = { + assert(get(dir) == null); + assert(node.get(dir.reverse) == null); + set(dir, node); + node.set(dir.reverse, self); + } + + + def end(dir : Dir) : Node = { + if (get(dir) == null) this; + else get(dir).end(dir); + } + } +} diff --git a/tests/pos/t5859.scala b/tests/pos/t5859.scala new file mode 100644 index 000000000..2a31e68ee --- /dev/null +++ b/tests/pos/t5859.scala @@ -0,0 +1,15 @@ + +class A { + def f(xs: List[Int], ys: AnyRef*) = () + def f(xs: AnyRef*) = () + + f() + f(List[AnyRef](): _*) + f(List(): _*) + f(Nil: _*) + f(Array(): _*) + f(Array[AnyRef](): _*) + f(List(1)) + f(List(1), Nil: _*) + f(List(1), Array(): _*) +} diff --git a/tests/pos/t5877.scala b/tests/pos/t5877.scala new file mode 100644 index 000000000..939013cd0 --- /dev/null +++ b/tests/pos/t5877.scala @@ -0,0 +1,14 @@ +package foo { + class Foo + + object Test { + new Foo().huzzah + } +} + +package object foo { + // Crasher: No synthetics for method EnrichedFoo2: synthetics contains + implicit class EnrichedFoo2(value: Foo) { + def huzzah = "" + } +} diff --git a/tests/pos/t5877b.scala b/tests/pos/t5877b.scala new file mode 100644 index 000000000..43a2ea2f0 --- /dev/null +++ b/tests/pos/t5877b.scala @@ -0,0 +1,13 @@ +package foo + +class Foo + +object Test { + new Foo().huzzah +} + +object `package` { + implicit class EnrichedFoo2(value: Foo) { + def huzzah = "" + } +} diff --git a/tests/pos/t5900a.scala b/tests/pos/t5900a.scala new file mode 100644 index 000000000..cb02f67fb --- /dev/null +++ b/tests/pos/t5900a.scala @@ -0,0 +1,9 @@ +case class Transition[S](x: S) + +object C + +object Test { + (??? : Any) match { + case Transition(C) => + } +} diff --git a/tests/pos/t5932.scala b/tests/pos/t5932.scala new file mode 100644 index 000000000..d824523d5 --- /dev/null +++ b/tests/pos/t5932.scala @@ -0,0 +1,15 @@ +class A + +case object B extends A + +object Test { + val x1 = (B: A) + + println(x1 == B) // no warning + println(B == x1) // no warning + + val x2 = (B: A with Product) + + println(x2 == B) // no warning + println(B == x2) // spurious warning: "always returns false" +} diff --git a/tests/pos/t596.scala b/tests/pos/t596.scala new file mode 100644 index 000000000..b1b5471b2 --- /dev/null +++ b/tests/pos/t596.scala @@ -0,0 +1,7 @@ +trait T1 { + protected abstract class C +} + +trait T2 extends T1 { + class D extends C +} diff --git a/tests/pos/t5967.scala b/tests/pos/t5967.scala new file mode 100644 index 000000000..cd219c031 --- /dev/null +++ b/tests/pos/t5967.scala @@ -0,0 +1,6 @@ +object Test { + def f(a: Int*) = a match { + case 0 :: Nil => "List(0)! My favorite Seq!" + case _ => a.toString + } +} diff --git a/tests/pos/t6014.scala b/tests/pos/t6014.scala new file mode 100644 index 000000000..26e258a27 --- /dev/null +++ b/tests/pos/t6014.scala @@ -0,0 +1,13 @@ +object Test { + case class CC[T](key: T) + type Alias[T] = Seq[CC[T]] + + def f(xs: Seq[CC[_]]) = xs map { case CC(x) => CC(x) } // ok + def g(xs: Alias[_]) = xs map { case CC(x) => CC(x) } // fails + // ./a.scala:11: error: missing parameter type for expanded function + // The argument types of an anonymous function must be fully known. (SLS 8.5) + // Expected type was: ? + // def g(xs: Alias[_]) = xs map { case CC(x) => CC(x) } // fails + // ^ + // one error found +} diff --git a/tests/pos/t604.scala b/tests/pos/t604.scala new file mode 100644 index 000000000..fb90d5ae3 --- /dev/null +++ b/tests/pos/t604.scala @@ -0,0 +1,8 @@ +object Test +{ + type T = Foo.type + object Foo + + def main(argv : Array[String]) : Unit = { + } +} diff --git a/tests/pos/t6089b.scala b/tests/pos/t6089b.scala new file mode 100644 index 000000000..9378a74a0 --- /dev/null +++ b/tests/pos/t6089b.scala @@ -0,0 +1,18 @@ +// this crazy code simply tries to nest pattern matches so that the last call is in a tricky-to-determine +// tail position (my initial tightenign of tailpos detection for SI-6089 ruled this out) +class BKTree { + @annotation.tailrec + final def -?-[AA](a: AA): Boolean = this match { + case BKTreeEmpty => false + case BKTreeNode(v) => { + val d = 1 + d == 0 || ( Map(1 -> this,2 -> this,3 -> this) get d match { + case None => false + case Some(w) => w -?- a // can tail call here (since || is shortcutting) + }) + } + } +} + +object BKTreeEmpty extends BKTree +case class BKTreeNode[A](v: A) extends BKTree diff --git a/tests/pos/t6117.scala b/tests/pos/t6117.scala new file mode 100644 index 000000000..6aca84f72 --- /dev/null +++ b/tests/pos/t6117.scala @@ -0,0 +1,19 @@ +package test + +trait ImportMe { + def foo(i: Int) = 1 + def foo(s: String) = 2 +} + +class Test(val importMe: ImportMe) { + import importMe._ + import importMe._ + + // A.scala:12: error: reference to foo is ambiguous; + // it is imported twice in the same scope by + // import importMe._ + // and import importMe._ + // println(foo(1)) + // ^ + println(foo(1)) +} diff --git a/tests/pos/t6123-explaintypes-implicits.scala b/tests/pos/t6123-explaintypes-implicits.scala new file mode 100644 index 000000000..86f522728 --- /dev/null +++ b/tests/pos/t6123-explaintypes-implicits.scala @@ -0,0 +1,13 @@ +object ImplicitBugReport { + trait Exp[+T] + trait CanBuildExp[-Elem, +To] extends (Exp[Elem] => To) + trait TraversableExp[T, ExpT <: Exp[T]] extends Exp[Traversable[T]] + + implicit def canBuildExp[T]: CanBuildExp[T, Exp[T]] = ??? + implicit def canBuildExpTrav[T, ExpT <: Exp[T]](implicit c: CanBuildExp[T, ExpT]): CanBuildExp[Traversable[T], TraversableExp[T, ExpT]] = ??? + def toExpTempl[T, That](t: T)(implicit c: CanBuildExp[T, That]): That = ??? + + def testBug(): Unit = { + val a1 = toExpTempl(Seq(1, 2, 3, 5)) + } +} diff --git a/tests/pos/t6145.scala b/tests/pos/t6145.scala new file mode 100644 index 000000000..4161a24b5 --- /dev/null +++ b/tests/pos/t6145.scala @@ -0,0 +1,11 @@ +object Test { + // the existential causes a cast and the cast makes searchClass not be in tail position + // can we get rid of the useless cast? + @annotation.tailrec + final def searchClass: Class[_] = { + "packageName" match { + case _ => + searchClass + } + } +} diff --git a/tests/pos/t6184.scala b/tests/pos/t6184.scala new file mode 100644 index 000000000..386399963 --- /dev/null +++ b/tests/pos/t6184.scala @@ -0,0 +1,7 @@ +trait Foo[TroubleSome] { + type T <: Foo[TroubleSome] + + this match { + case e: Foo[_]#T => ??? + } +} diff --git a/tests/pos/t6208.scala b/tests/pos/t6208.scala new file mode 100644 index 000000000..dac571346 --- /dev/null +++ b/tests/pos/t6208.scala @@ -0,0 +1,4 @@ +object Test { + val col = collection.mutable.Queue(1,2,3) + val WORK: collection.mutable.Queue[Int] = col filterNot (_ % 2 == 0) +} diff --git a/tests/pos/t6225.scala b/tests/pos/t6225.scala new file mode 100644 index 000000000..d3d30d9e1 --- /dev/null +++ b/tests/pos/t6225.scala @@ -0,0 +1,20 @@ + +package library.x { + class X { + class Foo + implicit val foo: Foo = new Foo + } +} +package library { + package object y extends library.x.X +} + +object ko { + import library.y.{Foo, foo} + implicitly[Foo] +} + +object ko2 { + import library.y._ + implicitly[Foo] +} diff --git a/tests/pos/t6231.scala b/tests/pos/t6231.scala new file mode 100644 index 000000000..1e5b4e0e1 --- /dev/null +++ b/tests/pos/t6231.scala @@ -0,0 +1,15 @@ +object Bug { + def bar(ev: Any) = { + trait X { + def qux = { () => ev } + } + new X {}.qux() + + // workaround + trait Y { + val ev2 = ev // manually capture `ev` so that `ev2` is added to the trait interface. + def qux = { () => ev2 } + } + } +} + diff --git a/tests/pos/t6231b.scala b/tests/pos/t6231b.scala new file mode 100644 index 000000000..b4ddfe785 --- /dev/null +++ b/tests/pos/t6231b.scala @@ -0,0 +1,8 @@ +class Test { + def f1(t: String) = { + trait T { + def xs = Nil map (_ => t) + } + () + } +} diff --git a/tests/pos/t6575a.scala b/tests/pos/t6575a.scala new file mode 100644 index 000000000..f128714da --- /dev/null +++ b/tests/pos/t6575a.scala @@ -0,0 +1,15 @@ +trait X { def foo: PartialFunction[Int, Int] } + +trait Y extends X { + // Inferred type was AbstractPartialFunction[Int, Int] with Serializable + abstract override def foo = { case i => super.foo(i) * 2 } +} +trait Z extends X { + // ditto + abstract override def foo = { case i => super.foo(i) + 3 } +} + +trait Comb extends Y with Z { + // ... which led to a type error here. + abstract override def foo: PartialFunction[Int, Int] = { case i => super.foo(i) - 2 } +} diff --git a/tests/pos/t6600.scala b/tests/pos/t6600.scala new file mode 100644 index 000000000..1e8137894 --- /dev/null +++ b/tests/pos/t6600.scala @@ -0,0 +1,8 @@ +final class Natural extends scala.math.ScalaNumber with scala.math.ScalaNumericConversions { + def intValue(): Int = 0 + def longValue(): Long = 0L + def floatValue(): Float = 0.0F + def doubleValue(): Double = 0.0D + def isWhole(): Boolean = false + def underlying() = this +} diff --git a/tests/pos/t661.scala b/tests/pos/t661.scala new file mode 100644 index 000000000..f2b76ee2f --- /dev/null +++ b/tests/pos/t661.scala @@ -0,0 +1,17 @@ +package test; + +object test { + abstract class A { + abstract class C { + type M; + def foo(n : M) : Unit = {} + } + } + trait B extends A { + type N; + trait CC extends super.C { + type M = N; + override def foo(n : M) : Unit = super.foo(n); + } + } +} diff --git a/tests/pos/t6664b.scala b/tests/pos/t6664b.scala new file mode 100644 index 000000000..a62286683 --- /dev/null +++ b/tests/pos/t6664b.scala @@ -0,0 +1,5 @@ +object T { + def A(s: String): A = new A(3, s) + def A(i: Int): A = A(i, "abc") + case class A(i: Int, s: String) +} diff --git a/tests/pos/t697.scala b/tests/pos/t697.scala new file mode 100644 index 000000000..6caea418d --- /dev/null +++ b/tests/pos/t697.scala @@ -0,0 +1,3 @@ +object test { + val x = 10 == 20 == 30 < 10; +} diff --git a/tests/pos/t6994.scala b/tests/pos/t6994.scala new file mode 100644 index 000000000..d70719642 --- /dev/null +++ b/tests/pos/t6994.scala @@ -0,0 +1,8 @@ +object Test { + object NF { + def unapply(t: Throwable): Option[Throwable] = None + } + val x = (try { None } catch { case NF(ex) => None }) getOrElse 0 + // Was emitting a spurious warning post typer: + // "This catches all Throwables. If this is really intended, use `case ex6 : Throwable` to clear this warning." +} diff --git a/tests/pos/t7011.scala b/tests/pos/t7011.scala new file mode 100644 index 000000000..f1f71b9be --- /dev/null +++ b/tests/pos/t7011.scala @@ -0,0 +1,7 @@ +object bar { + def foo: Unit = { + lazy val x = 42 + + {()=>x} + } +} diff --git a/tests/pos/t703.scala b/tests/pos/t703.scala new file mode 100644 index 000000000..b24d70c92 --- /dev/null +++ b/tests/pos/t703.scala @@ -0,0 +1,29 @@ +object Go { + trait A { + def f : Unit; // = Console.println("A"); + } + trait B extends A { + abstract override def f = { + super.f; + Console.println("B"); + } + } + trait C extends A { + abstract override def f = { + super.f; + Console.println("C"); + } + } + trait D extends B with C { + abstract override def f = { + super.f; + } + } + class Super extends A { + def f: Unit = Console.println("A") + } + def main(args : Array[String]) : Unit = { + object d extends Super with D + d.f; + } +} diff --git a/tests/pos/t704.scala b/tests/pos/t704.scala new file mode 100644 index 000000000..aedd8c03a --- /dev/null +++ b/tests/pos/t704.scala @@ -0,0 +1,23 @@ +trait D { + private val x = "xxxx should appear twice" + private object xxxx { Console.println(x) } + def get_xxxx: AnyRef = xxxx +} + +trait E extends D { + def f(): Unit = { + val y = "yyyy should appear twice" + object yyyy { + val x1 = get_xxxx + Console.println(y) + } + yyyy + } +} +class C extends E {} +object Go extends D { + def main(args : Array[String]): Unit = { + new C().f() + new C().f() + } +} diff --git a/tests/pos/t7126.scala b/tests/pos/t7126.scala new file mode 100644 index 000000000..edac56d28 --- /dev/null +++ b/tests/pos/t7126.scala @@ -0,0 +1,11 @@ +import language._ + +object Test { + type T = Any + boom(???): Option[T] // SOE + def boom[CC[U]](t : CC[T]): Option[CC[T]] = None + + // okay + foo(???): Option[Any] + def foo[CC[U]](t : CC[Any]): Option[CC[Any]] = None +} diff --git a/tests/pos/t7226.scala b/tests/pos/t7226.scala new file mode 100644 index 000000000..1b7e2549c --- /dev/null +++ b/tests/pos/t7226.scala @@ -0,0 +1,26 @@ +trait HK { + type Rep[X] + + // okay + def unzip2[A, B](ps: Rep[List[(A, B)]]): Unit + unzip2(null.asInstanceOf[Rep[List[(Int, String)]]]) + + // okay + def unzipHK[A, B, C[_]](ps: Rep[C[(A, B)]]): Unit + unzipHK(null.asInstanceOf[Rep[List[(Int, String)]]]) + + def unzipHKRet0[A, C[_]](ps: C[A]): C[Int] + def ls: List[String] + unzipHKRet0(ls) + + // fail + def unzipHKRet[A, C[_]](ps: Rep[C[A]]): Rep[C[Int]] + def rls: Rep[List[String]] + unzipHKRet(rls) +} + +trait HK1 { + type Rep[A] + def unzip1[A, B, C[_]](ps: Rep[C[(A, B)]]): (Rep[C[A]], Rep[C[B]]) + def doUnzip1[A, B](ps: Rep[List[(A, B)]]) = unzip1(ps) +} diff --git a/tests/pos/t7285a.scala b/tests/pos/t7285a.scala new file mode 100644 index 000000000..23b52f595 --- /dev/null +++ b/tests/pos/t7285a.scala @@ -0,0 +1,92 @@ +sealed abstract class Base + +object Test { + case object Up extends Base + + def foo(d1: Base) = + d1 match { + case Up => + } + + // Sealed subtype: ModuleTypeRef <empty>.this.Test.Up.type + // Pattern: UniqueThisType Test.this.type +} + + +object Test1 { + sealed abstract class Base + + object Base { + case object Down extends Base { + } + + case object Up extends Base { + } + + locally { + + (d1: Base, d2: Base) => + (d1, d2) match { + case (Up, Up) | (Down, Down) => false + case (Down, Up) => true + case (Up, Down) => false + } + } + } +} + +object Test2 { + sealed abstract class Base + + object Base { + case object Down extends Base { + } + + case object Up extends Base { + } + + locally { + (d1: Base, d2: Base) => + (d1) match { + case Up | Down => false + } + } + } +} + +object Test3 { + sealed abstract class Base + + object Base { + case object Down extends Base + + locally { + (d1: Base, d2: Base) => + (d1, d2) match { + case (Down, Down) => false + } + } + } +} + +object Test4 { + sealed abstract class Base + + object Base { + case object Down extends Base { + } + + case object Up extends Base { + } + + } + import Test4.Base._ + locally { + (d1: Base, d2: Base) => + (d1, d2) match { + case (Up, Up) | (Down, Down) => false + case (Down, Test4.Base.Up) => true + case (Up, Down) => false + } + } +} diff --git a/tests/pos/t7475a.scala b/tests/pos/t7475a.scala new file mode 100644 index 000000000..810ce9a05 --- /dev/null +++ b/tests/pos/t7475a.scala @@ -0,0 +1,11 @@ +trait AbstractPublic { + def queue: Any +} +trait ConcretePrivate { + private val queue: Any = () +} + +abstract class Mix + extends ConcretePrivate with AbstractPublic { + final def queue: Any = () +} diff --git a/tests/pos/t7475b.scala b/tests/pos/t7475b.scala new file mode 100644 index 000000000..a34743b8b --- /dev/null +++ b/tests/pos/t7475b.scala @@ -0,0 +1,8 @@ +trait U { +} + +trait T { + type TT = Any with T with U + private val priv = 0 + (??? : TT).priv +} diff --git a/tests/pos/t7520.scala b/tests/pos/t7520.scala new file mode 100644 index 000000000..747f5278e --- /dev/null +++ b/tests/pos/t7520.scala @@ -0,0 +1,10 @@ +class A { + val x: Singleton with this.type = this + val y: this.type = x +} + +class B { + val x = "" + val xs: x.type with Singleton = x + val y: x.type = xs +} diff --git a/tests/pos/t758.scala b/tests/pos/t758.scala new file mode 100644 index 000000000..160bf3717 --- /dev/null +++ b/tests/pos/t758.scala @@ -0,0 +1,7 @@ +trait A { type T; type M >: T } +trait B extends A { + val x : String; + val u : A { type T = B.this.T } ; + type T = x.type; + type M = u.M +} diff --git a/tests/pos/t7591.scala b/tests/pos/t7591.scala new file mode 100644 index 000000000..dd127b881 --- /dev/null +++ b/tests/pos/t7591.scala @@ -0,0 +1,86 @@ +/* NEST (New Scala Test) + * Copyright 2007-2013 LAMP/EPFL + * @author Paul Phillips + */ + +import scala.tools.cmd._ + +/** A sample command specification for illustrative purposes. + * First take advantage of the meta-options: + * + * // this command creates an executable runner script "demo" + * % scala scala.tools.cmd.Demo --self-update demo + * + * // this one creates and sources a completion file - note backticks + * % `./demo --bash` + * + * // and now you have a runner with working completion + * % ./demo --<tab> + * --action --defint --int + * --bash --defstr --str + * --defenv --self-update --unary + * + * The normal option configuration is plausibly self-explanatory. + */ +trait DemoSpec extends Spec with Meta.StdOpts with Interpolation { + lazy val referenceSpec = DemoSpec + lazy val programInfo = Spec.Info("demo", "Usage: demo [<options>]", "scala.tools.cmd.Demo") + + help("""Usage: demo [<options>]""") + heading("Unary options:") + + val optIsUnary = "unary" / "a unary option" --? ; + ("action" / "a body which may be run") --> println("Hello, I am the --action body.") + + heading("Binary options:") + val optopt = "str" / "an optional String" --| + val optoptInt = ("int" / "an optional Int") . --^[Int] + val optEnv = "defenv" / "an optional String" defaultToEnv "PATH" + val optDefault = "defstr" / "an optional String" defaultTo "default" + val optDefaultInt = "defint" / "an optional Int" defaultTo -1 + val optExpand = "alias" / "an option which expands" expandTo ("--int", "15") +} + +object DemoSpec extends DemoSpec with Property { + lazy val propMapper = new PropertyMapper(DemoSpec) + + type ThisCommandLine = SpecCommandLine + def creator(args: List[String]) = + new SpecCommandLine(args) { + override def errorFn(msg: String) = { println("Error: " + msg) ; sys.exit(0) } + } +} + +class Demo(args: List[String]) extends DemoSpec with Instance { +// TODO NEEDS MANUAL CHANGE (early initializers) +// BEGIN copied early initializers +val parsed = DemoSpec(args: _*) +// END copied early initializers + + import java.lang.reflect._ + + def helpMsg = DemoSpec.helpMsg + def demoSpecMethods = this.getClass.getMethods.toList + private def isDemo(m: Method) = (m.getName startsWith "opt") && !(m.getName contains "$") && (m.getParameterTypes.isEmpty) + + def demoString(ms: List[Method]) = { + val longest = ms map (_.getName.length) max + val formatStr = " %-" + longest + "s: %s" + val xs = ms map (m => formatStr.format(m.getName, m.invoke(this))) + + xs mkString ("Demo(\n ", "\n ", "\n)\n") + } + + override def toString = demoString(demoSpecMethods filter isDemo) +} + +object Demo { + def main(args: Array[String]): Unit = { + val runner = new Demo(args.toList) + + if (args.isEmpty) + println(runner.helpMsg) + + println(runner) + } +} diff --git a/tests/pos/t7782.scala b/tests/pos/t7782.scala new file mode 100644 index 000000000..9b98f6ac6 --- /dev/null +++ b/tests/pos/t7782.scala @@ -0,0 +1,25 @@ +package pack + +object Test { + import O.empty + empty // this will trigger completion of `test` + // with skolemizationLevel = 1 +} + +object O { + // order matters (!!!) + + // this order breaks under 2.10.x + def empty[E]: C[E] = ??? + def empty(implicit a: Any): Any = ??? +} + +abstract class C[E] { + def foo[BB](f: BB): Unit + def test[B](f: B): Any = foo(f) + // error: no type parameters for method foo: (<param> f: BB)scala.this.Unit exist so that it can be applied to arguments (B&1) + // --- because --- + // argument expression's type is not compatible with formal parameter type; + // found : B&1 + // required: ?BB +} diff --git a/tests/pos/t7782b.scala b/tests/pos/t7782b.scala new file mode 100644 index 000000000..5b1979ec1 --- /dev/null +++ b/tests/pos/t7782b.scala @@ -0,0 +1,25 @@ +package pack + +object Test { + import O.empty + empty // this will trigger completion of `test` + // with skolemizationLevel = 1 +} + +object O { + // order matters (!!!) + + // this order breaks under 2.11.x + def empty(implicit a: Any): Any = ??? + def empty[E]: C[E] = ??? +} + +abstract class C[E] { + def foo[BB](f: BB): Unit + def test[B](f: B): Any = foo(f) + // error: no type parameters for method foo: (<param> f: BB)scala.this.Unit exist so that it can be applied to arguments (B&1) + // --- because --- + // argument expression's type is not compatible with formal parameter type; + // found : B&1 + // required: ?BB +} diff --git a/tests/pos/t7785.scala b/tests/pos/t7785.scala new file mode 100644 index 000000000..1de693d13 --- /dev/null +++ b/tests/pos/t7785.scala @@ -0,0 +1,34 @@ +import scala.language._ + +trait R[+Repr] + +trait TraversableOps { + implicit val R: R[Nothing] = ??? + + // Removing the implicit parameter in both fixes the crash + // removing it into one only gives a valid compiler error. + trait OpsDup1[Repr] { + def force(implicit bf: R[Repr]): Any + } + + trait Ops[Repr] extends OpsDup1[Repr] { + def force(implicit bf: R[Repr], dummy: DummyImplicit): Any + } + + implicit def ct2ops[T, C[+X]](t: C[T]): + Ops[C[T]] + + def force[T](t: Option[T]) = + // ct2ops(t).force + t.force //Fails compilation on 2.10.2. + + + /* To get a closer look at the crash: + :power + val foo = typeOf[C].member(TermName("foo")) + val pt = analyzer.HasMember(TermName("force")) + val instantiated = foo.info.finalResultType.instantiateTypeParams(foo.typeParams, foo.typeParams.map(TypeVar(_))) + instantiated <:< pt + */ + def foo[T, C[+X]]: Ops[C[T]] +} diff --git a/tests/pos/t7853.scala b/tests/pos/t7853.scala new file mode 100644 index 000000000..b0e9221e2 --- /dev/null +++ b/tests/pos/t7853.scala @@ -0,0 +1,11 @@ +trait S { + trait T { + this: Any => + + trait U { + trait V { + S.this + } + } + } +} diff --git a/tests/pos/t788.scala b/tests/pos/t788.scala new file mode 100644 index 000000000..19638dd17 --- /dev/null +++ b/tests/pos/t788.scala @@ -0,0 +1,19 @@ +package test; + +trait Test { + type Node <: NodeImpl; + trait NodeImpl; + type Expression <: Node with ExpressionImpl; + trait ExpressionImpl extends NodeImpl { + def self : Expression; + } + type Named <: Node with NamedImpl; + trait NamedImpl extends NodeImpl { + def self : Named; + } + def asExpression(e : ExpressionImpl) : Named = { + e match { + case f : NamedImpl => f.self; + } + } +} diff --git a/tests/pos/t7928.scala b/tests/pos/t7928.scala new file mode 100644 index 000000000..d9e29935b --- /dev/null +++ b/tests/pos/t7928.scala @@ -0,0 +1,16 @@ +trait OuterTrait { + trait InnerTrait { + type Element + type Collection <: Iterable[Inner.Element] + } + + val Inner: InnerTrait + +} + +object OuterObject extends OuterTrait { + object Inner extends InnerTrait { + type Element = String + override type Collection = Seq[Inner.Element] + } +} diff --git a/tests/pos/t796.scala b/tests/pos/t796.scala new file mode 100644 index 000000000..b1463ed92 --- /dev/null +++ b/tests/pos/t796.scala @@ -0,0 +1,26 @@ +/** I know what I am doing is wrong -- since I am about to look into + * this bug, I add a test in pending/pos... however, I am afraid that + * once this bug is fixed, this test case might go into test/pos + * there it adds to the huge number of tiny little test cases. + * + * Ideally, an option in the bugtracking system would automatically + * handle "pos" bugs. + */ +object Test extends App { + + object Twice { + def apply(x: Int) = x * 2 + def unapply(x: Int): Option[Tuple1[Int]] = + if (x % 2 == 0) Some(Tuple1(x / 2)) + else None + } + + def test(x: Int) = x match { + case Twice(y) => "x is two times " + y + case _ => "x is odd" + } + + Console.println(test(3)) + Console.println(test(4)) + +} diff --git a/tests/pos/t7983.scala b/tests/pos/t7983.scala new file mode 100644 index 000000000..fbeb7d3c5 --- /dev/null +++ b/tests/pos/t7983.scala @@ -0,0 +1,31 @@ +package foo.bar.baz // the package nesting level material to this bug + +class DivergenceTest { + + trait ColumnBase[T] + + trait ShapeLevel + trait Flat extends ShapeLevel + trait Lower extends Flat + + class Shape2[Level <: ShapeLevel, -M, U] + + implicit final def columnBaseShape[Level >: Flat <: ShapeLevel, T, C <: ColumnBase[_]] + (implicit ev: C <:< ColumnBase[T] + ): Shape2[Level, C, T] = ??? + + implicit final def intShape[Level <: ShapeLevel, T]: Shape2[Level, Int, Int] = ??? + implicit final def tuple2Shape[Level <: ShapeLevel, M1,M2, U1,U2] + (implicit u1: Shape2[_ <: Level, M1, U1], + u2: Shape2[_ <: Level, M2, U2] + ): Shape2[Level, (M1,M2), (U1,U2)] = ??? + + def foo: Unit = { + class Coffees extends ColumnBase[Int] + + def map1[F, T](f: F)(implicit shape: Shape2[_ <: Flat, F, T]) = ??? + + map1(((1, null: Coffees), 1)) + map1(((null: Coffees, 1), 1)) // fails with implicit divergence error in 2.11.0-M6, works under 2.10.3 + } +} diff --git a/tests/pos/t802.scala b/tests/pos/t802.scala new file mode 100644 index 000000000..50a948251 --- /dev/null +++ b/tests/pos/t802.scala @@ -0,0 +1,27 @@ +package test; +trait Test { + abstract class BracesImpl { + type Singleton; + type Brace <: Singleton with BraceImpl; + trait BraceImpl; + trait ForFile; + } + abstract class ParensImpl extends BracesImpl { + type Brace <: Singleton with BraceImpl; + trait BraceImpl2 extends super.BraceImpl; + } + val parens : ParensImpl; + abstract class BracksImpl extends BracesImpl { + type Brace <: Singleton with BraceImpl; + trait BraceImpl2 extends super.BraceImpl; + } + val bracks : BracksImpl; + trait File { + def parens0 : parens.BraceImpl; + def bracks0 : bracks.BraceImpl; + def braces(b : BracesImpl) = b match { + case b if b == parens => parens0; + case b if b == bracks => bracks0; + } + } +} diff --git a/tests/pos/t8023b.scala b/tests/pos/t8023b.scala new file mode 100644 index 000000000..94c9b2f8d --- /dev/null +++ b/tests/pos/t8023b.scala @@ -0,0 +1,2 @@ +// this fails with naive attempts to fix SI-8023 +trait T[A <: T[A]] diff --git a/tests/pos/t8045.scala b/tests/pos/t8045.scala new file mode 100644 index 000000000..21154e386 --- /dev/null +++ b/tests/pos/t8045.scala @@ -0,0 +1,17 @@ +object Test extends App { + case class Number(i: Int) + + object UnliftNumber { + def unapply(t: Any): Option[Number] = t match { + case i: Int => Some(Number(i)) + case _ => None + } + } + + def eval(expr: Any): Option[Number] = expr match { + case UnliftNumber(n) => Some(n) + case _ => None + } + + println(eval(1)) +} diff --git a/tests/pos/t805.scala b/tests/pos/t805.scala new file mode 100644 index 000000000..a1260a834 --- /dev/null +++ b/tests/pos/t805.scala @@ -0,0 +1,19 @@ +trait MatcherYYY { + trait NodeImpl; + trait Matchable extends NodeImpl { + protected def doMatch : Unit = {} + } +} +trait BraceMatcherXXX extends MatcherYYY { + trait NodeImpl2 extends super.NodeImpl { + def doMatch (braces : BracePair) : Unit + } + trait BracePair { + trait BraceImpl extends NodeImpl2 with Matchable { + override def doMatch : Unit = { + super.doMatch; + (); + } + } + } +} diff --git a/tests/pos/t8128.scala b/tests/pos/t8128.scala new file mode 100644 index 000000000..b6f76691b --- /dev/null +++ b/tests/pos/t8128.scala @@ -0,0 +1,15 @@ +object G { + def unapply(m: Any): Option[_] = Some("") +} + +object H { + def unapplySeq(m: Any): Option[Seq[_]] = None +} + +object Test { + (0: Any) match { + case G(v) => v + case H(v) => v + case _ => + } +} diff --git a/tests/pos/t8177a.scala b/tests/pos/t8177a.scala new file mode 100644 index 000000000..7e2cfb386 --- /dev/null +++ b/tests/pos/t8177a.scala @@ -0,0 +1,9 @@ +// exercise coevolveSym +trait Thing { type A; var p: A = _ } +class AA[T](final val x: Thing { type A = T }) { + def foo: x.A = ??? +} + +class B extends AA[Int](null) { + override def foo: B.this.x.A = super.foo +} diff --git a/tests/pos/t8187.scala b/tests/pos/t8187.scala new file mode 100644 index 000000000..84b8cd0f4 --- /dev/null +++ b/tests/pos/t8187.scala @@ -0,0 +1,6 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + val tyn: TypeName = (??? : TypeSymbol).name + val ten: TermName = (??? : TermSymbol).name +} diff --git a/tests/pos/t8219.scala b/tests/pos/t8219.scala new file mode 100644 index 000000000..e1653b623 --- /dev/null +++ b/tests/pos/t8219.scala @@ -0,0 +1,15 @@ +trait Equalizer[T] +trait Gen[A] + +class Broken { + implicit def const[T](x: T): Gen[T] = ??? + implicit def convertToEqualizer[T](left: T): Equalizer[T] = ??? + + def in(a: Any) = () + in { + import scala.None // any import will do.. + "" == "" // this no longer triggers the bug, as Object#== now overrides Any#== + } + + // We can still trigger the bug with a structural type, see pending/neg/t8219.scala +} diff --git a/tests/pos/t8367.scala b/tests/pos/t8367.scala new file mode 100644 index 000000000..f0c329211 --- /dev/null +++ b/tests/pos/t8367.scala @@ -0,0 +1,11 @@ +package java.lang + +// SI-8367 shows something is wrong with primaryConstructor and it was made worse with the fix for SI-8192 +// perhaps primaryConstructor should not return NoSymbol when isJavaDefined +// or, perhaps isJavaDefined should be refined (the package definition above is pretty sneaky) +// also, why does this only happen for a (scala-defined!) class with this special name? +// (there are a couple of others: CloneNotSupportedException,InterruptedException) +class Throwable + +// class CloneNotSupportedException +// class InterruptedException diff --git a/tests/pos/t8369a.scala b/tests/pos/t8369a.scala new file mode 100644 index 000000000..13046007f --- /dev/null +++ b/tests/pos/t8369a.scala @@ -0,0 +1,5 @@ +object Bug { + trait Sys[S] + def test[S <: Sys[S]] = read[S]() + def read[S <: Sys[S]](baz: Any = 0): Some[S] = ??? +} diff --git a/tests/pos/t873.scala b/tests/pos/t873.scala new file mode 100644 index 000000000..b8c50afd3 --- /dev/null +++ b/tests/pos/t873.scala @@ -0,0 +1,10 @@ +abstract class Foo { + + val x:Option[List[String]] + val y:List[Int] + + val z = (0:Any) match { + case 1 => x + case 2 => y + } +} diff --git a/tests/pos/t911.scala b/tests/pos/t911.scala new file mode 100644 index 000000000..cfa4f49dc --- /dev/null +++ b/tests/pos/t911.scala @@ -0,0 +1,6 @@ +object Test { + def foo: Any = { + case class Foo() {} + Foo; + } +} diff --git a/tests/pos/tcpoly_infer_ticket1864.scala b/tests/pos/tcpoly_infer_ticket1864.scala new file mode 100644 index 000000000..4b7c7a223 --- /dev/null +++ b/tests/pos/tcpoly_infer_ticket1864.scala @@ -0,0 +1,51 @@ +import scala.collection.mutable.{Buffer, ArrayBuffer} + +class RichBuffer[T, B[U] <: Buffer[U]](buffer: Buffer[T]) { + def mymap[S](f: T => S)(implicit rv: B[S]): B[S] = { + buffer.foreach{ e => + rv += f(e) + } + rv + } +} + +object App { + def mymap2[T, B[U] <: Buffer[U], S](buffer: B[T], f: T => S)(implicit rv: B[S]): B[S] = { + buffer.foreach{ e => + rv += f(e) + } + rv + } + + def mymap3[T, B <: Buffer[T], S](buffer: B, f: T => T)(implicit rv: B): B = { + buffer.foreach{ e => + rv += f(e) + } + rv + } + + def mymap4[T, B[U] <: Buffer[U], S](buffer: B[T])(f: T => S) (implicit rv: B[S]): B[S] = { + buffer.foreach{ e => + rv += f(e) + } + rv + } + + + def main(args: Array[String]): Unit = { + implicit def richBuffer[T, B[U] <: Buffer[U]](buffer: B[T]): RichBuffer[T, B] = + new RichBuffer[T, B](buffer) + + implicit val rv: scala.collection.mutable.ArrayBuffer[Int] = new ArrayBuffer[Int] + val buf = new ArrayBuffer[Int] + (1 to 5).foreach(buf += _) + buf.mymap(x => x*x) + richBuffer(buf).mymap[Int](x => x*x) + richBuffer[Int, ArrayBuffer](buf).mymap[Int](x => x*x) + mymap2(buf, (x: Int) => x*x) + mymap2[Int, ArrayBuffer, Int](buf, (x: Int) => x*x) + // mymap3(buf, x => x*x) // compiler error + mymap3(buf, (x: Int) => x*x) + mymap4(buf)(x => x*x) + } +} diff --git a/tests/pos/tcpoly_ticket2096.scala b/tests/pos/tcpoly_ticket2096.scala new file mode 100644 index 000000000..d2387b36b --- /dev/null +++ b/tests/pos/tcpoly_ticket2096.scala @@ -0,0 +1,30 @@ +// smallest expression of monad i can find +trait MBrace[C[X] <: MBrace[C,X],A] { + def nest( a : A ) : C[A] + def flatten[T <: C[C[A]]]( bsq : T ) : C[A] +} + +// a monad that is a Seq +trait MBraceSeq[C[X] <: MBrace[C,X] with Seq[X],A] extends MBrace[C,A] + +// one of the simplest witnesses of monad i can find +case class MSequitor[A]( a_ : A* ) extends Seq[A] with MBrace[MSequitor,A] +{ + override def nest( a : A ) = new MSequitor[A]( a ) + override def flatten[T <: MSequitor[MSequitor[A]]]( bsq : T ) : MSequitor[A] = { + (new MSequitor[A]( ) /: bsq)( { + ( acc : MSequitor[A], e : MSequitor[A] ) => ( acc ++ e ).asInstanceOf[MSequitor[A]] + } ) + } + override def length = a_.length + override def iterator = a_.iterator + override def apply( n : Int ) = a_.apply( n ) +} + +// type arguments [MSequitor,A] do not conform to trait MBraceSeq's type parameter bounds [C[_] <: MBrace[C,A] with Seq[A],A] +// a statement of the instance relation +class MBraceSequitor[A] extends MBraceSeq[MSequitor,A] { + val empty : MSequitor[A] = new MSequitor[A]( ) + override def nest( a : A ) = empty.nest( a ) + override def flatten[T <: MSequitor[MSequitor[A]]]( bsq : T ): MSequitor[A] = empty.flatten( bsq ) +} diff --git a/tests/pos/tcpoly_variance_pos.scala b/tests/pos/tcpoly_variance_pos.scala new file mode 100644 index 000000000..b63abce20 --- /dev/null +++ b/tests/pos/tcpoly_variance_pos.scala @@ -0,0 +1,7 @@ +class A[m[+x]] { + def str: m[Object] = sys.error("foo") +} + +class B[m[+x]] extends A[m] { + override def str: m[String] = sys.error("foo") +} diff --git a/tests/pos/ted.scala b/tests/pos/ted.scala new file mode 100644 index 000000000..314f10932 --- /dev/null +++ b/tests/pos/ted.scala @@ -0,0 +1,18 @@ +object App +{ + def exponentiate(base : Double, exponent : Double) : Double = + (base, exponent) match + { + case (0, 0) => 1.0 + case (b, 0) => 1.0 + case (b, 1) => b + case (b, e) => b * exponentiate(b, e - 1) + } + + + + def main(args : Array[String]) = + System.out.println(exponentiate(2, 2)) + +} + diff --git a/tests/pos/test4.scala b/tests/pos/test4.scala new file mode 100644 index 000000000..4fe65a8f1 --- /dev/null +++ b/tests/pos/test4.scala @@ -0,0 +1,47 @@ +package test; + +trait C {} +trait D {} +trait E {} + +object test { + def c: C = c; + def d: D = d; + def e: E = e; +} + +import test._; + +trait S extends ooo.I[D] { + def bar: E = foo(c,d); +} + +class O[X]() { + trait I[Y] { + def foo(x: X, y: Y): E = e; + } + val i:I[E] = null; + val j:I[X] = null; +} + +object ooo extends O[C]() { + + def main = { + val s: S = null; + import s._; + foo(c,d); + ooo.i.foo(c,e); + ooo.j.foo(c,c); + bar + } +} + +class Main() { + val s: S = null; + import s._; + foo(c,d); + ooo.i.foo(c,e); + ooo.j.foo(c,c); + bar; +} + diff --git a/tests/pos/test5.scala b/tests/pos/test5.scala new file mode 100644 index 000000000..c19478048 --- /dev/null +++ b/tests/pos/test5.scala @@ -0,0 +1,68 @@ +import scala._; + +object test { + + trait F[If] {} + + def f[Jf](h: Jf):F[Jf] = f[Jf](h); + + trait G[Ig] {} + + def g[Jg](h: Jg):G[Jg] = g[Jg](h); + + class M[P]() { + abstract class I[X]() { + // Methods to check the type X and P as seen from instances of I + def chk_ix(x: X): Unit = (); + def chk_ip(p: P): Unit; + + // Value with type X as seen from instances of I + def val_ix: X = val_ix; + } + + val i:I[G[P]] = null; + + // Values with types P and i.X as seen from instances of M + def val_mp: P = val_mp; + def val_mix: G[P] = g[P](val_mp); + } + + class N[Q]() extends M[F[Q]]() { + val j:J[G[Q]] = null; + + abstract class J[Y]() extends I[G[Y]]() { + // Values with types Y and X as seen from instances of J + def val_jy: Y = val_jy; + def val_jx: G[Y] = g[Y](val_jy); + + // Check type P + chk_ip(val_mp); + chk_ip(val_np); + } + + // Values with types Q, X.P, i.X, j.Y and j.X as seen from instances of N + def val_nq: Q = val_nq; + def val_np: F[Q] = f[Q](val_nq); + def val_nix: G[F[Q]] = g[F[Q]](val_np); + def val_njy: G[Q] = g[Q](val_nq); + def val_njx: G[G[Q]] = g[G[Q]](val_njy); + + // Check type i.P + i.chk_ip(val_mp); + i.chk_ip(val_np); + + // Check type j.P + j.chk_ip(val_mp); + j.chk_ip(val_np); + + // Check type i.X + i.chk_ix(i.val_ix); + i.chk_ix(val_mix); + i.chk_ix(val_nix); + + // Check j.X + j.chk_ix(j.val_ix); + j.chk_ix(j.val_jx); + j.chk_ix(val_njx); + } +} diff --git a/tests/pos/test5refine.scala b/tests/pos/test5refine.scala new file mode 100644 index 000000000..09ea179da --- /dev/null +++ b/tests/pos/test5refine.scala @@ -0,0 +1,75 @@ +import scala._; + +object test { + + abstract trait F { type If; } + + def f[Jf](h: Jf):F { type If = Jf } = f[Jf](h); + + abstract trait G { type Ig; } + + def g[Jg](h: Jg):G { type Ig = Jg } = g[Jg](h); + + abstract class M() { + type P; + abstract class I() { + type X; + + // Methods to check the type X and P as seen from instances of I + def chk_ix(x: X): Unit = {} + def chk_ip(p: P): Unit = {} + + // Value with type X as seen from instances of I + def val_ix: X = val_ix; + } + + val i: I { type X = G { type Ig = P } } = null; + + // Values with types P and i.X as seen from instances of M + def val_mp: P = val_mp; + def val_mix: G { type Ig = P } = g[P](val_mp); + } + + abstract class N() extends M() { + type Q; + type P = F { type If = Q }; + val j:J { type Y = G { type Ig = Q } } = null; + + abstract class J() extends I() { + type Y; + type X = G { type Ig = Y; }; + // Values with types Y and X as seen from instances of J + def val_jy: Y = val_jy; + def val_jx: G { type Ig = Y; } = g[Y](val_jy); + + // Check type P + chk_ip(val_mp); + chk_ip(val_np); + } + + // Values with types Q, X.P, i.X, j.Y and j.X as seen from instances of N + def val_nq: Q = val_nq; + def val_np: F { type If = Q } = f[Q](val_nq); + def val_nix: G { type Ig = F { type If = Q } } = g[F { type If = Q }](val_np); + def val_njy: G { type Ig = Q; } = g[Q](val_nq); + def val_njx: G { type Ig = G { type Ig = Q }} = g[G { type Ig = Q; }](val_njy); + + // Check type i.P + i.chk_ip(val_mp); + i.chk_ip(val_np); + + // Check type j.P + j.chk_ip(val_mp); + j.chk_ip(val_np); + + // Check type i.X + i.chk_ix(i.val_ix); + i.chk_ix(val_mix); + i.chk_ix(val_nix); + + // Check j.X + j.chk_ix(j.val_ix); + j.chk_ix(j.val_jx); + j.chk_ix(val_njx); + } +} diff --git a/tests/pos/typealiases.scala b/tests/pos/typealiases.scala new file mode 100644 index 000000000..93d1dce4d --- /dev/null +++ b/tests/pos/typealiases.scala @@ -0,0 +1,20 @@ +package foo + +trait Test[T] { + type Check[T] = Array[T] => Unit; + type MyPair[S] = (T, S) + + val pair1: (T, Int) + val pair: MyPair[Int] = pair1 + + def check(xs: Array[T], c: Check[T]) = c(xs) + def check2[S](xs: Array[S], c: Check[S]) = c(xs) +} + +object main extends Test[Int] { + val pair1 = (1,1) + + implicit def topair(x: Int): Tuple2[Int, Int] = (x,x) + val pair2: MyPair[Int] = 1 + val x: Short = 1 +} diff --git a/tests/pos/typerep-stephane.scala b/tests/pos/typerep-stephane.scala new file mode 100644 index 000000000..2cb899591 --- /dev/null +++ b/tests/pos/typerep-stephane.scala @@ -0,0 +1,48 @@ +object typerep { + + class TypeRep[T] { + def getType: TypeRep[T] = this + } + + object BooleanRep extends TypeRep[Boolean] { + override def toString = "Boolean" + } + object CharRep extends TypeRep[Char] { + override def toString = "Char" + } + object IntRep extends TypeRep[Int] { + override def toString = "Int" + } + object LongRep extends TypeRep[Long] { + override def toString = "Long" + } + object FloatRep extends TypeRep[Float] { + override def toString = "Float" + } + object DoubleRep extends TypeRep[Double] { + override def toString = "Double" + } + class ListRep[U, T <: List[U]](val elemRep: TypeRep[U]) extends TypeRep[T] { + override def toString = "List[" + elemRep + "]" + } + + implicit def typeRep(x: Boolean): TypeRep[Boolean] = BooleanRep + implicit def typeRep(x: Char ): TypeRep[Char ] = CharRep + implicit def typeRep(x: Long ): TypeRep[Long ] = LongRep + implicit def typeRep(x: Float ): TypeRep[Float ] = FloatRep + implicit def typeRep(x: Double ): TypeRep[Double ] = DoubleRep + implicit def typeRep(x: Int ): TypeRep[Int ] = IntRep +/* + implicit def typeRep[T](xs: List[T])(implicit rep: T => TypeRep[T]): TypeRep[List[T]] = + new ListRep(rep(xs.head)) +*/ + implicit def typeRep[T <% TypeRep[T]](xs: List[T]): TypeRep[List[T]] = + new ListRep(xs.head) + +} + +object test extends App { + import typerep._ + println(3.getType) + println(List(3).getType) +} diff --git a/tests/pos/virtpatmat_alts_subst.scala b/tests/pos/virtpatmat_alts_subst.scala new file mode 100644 index 000000000..e27c52f9c --- /dev/null +++ b/tests/pos/virtpatmat_alts_subst.scala @@ -0,0 +1,6 @@ +case class Foo(s: String) { + def appliedType(tycon: Any) = + tycon match { + case Foo(sym @ ("NothingClass" | "AnyClass")) => println(sym) + } +} diff --git a/tests/pos/virtpatmat_exist1.scala b/tests/pos/virtpatmat_exist1.scala new file mode 100644 index 000000000..6cad017b0 --- /dev/null +++ b/tests/pos/virtpatmat_exist1.scala @@ -0,0 +1,24 @@ +import annotation.unchecked.{ uncheckedVariance=> uV } +import scala.collection.immutable.{ListMap, HashMap, ListSet, HashSet} + +object Test { + class HashMapCollision1[A, +B](var hash: Int, var kvs: ListMap[A, B @uV]) extends HashMap[A, B @uV] + class HashSetCollision1[A](var hash: Int, var ks: ListSet[A]) extends HashSet[A] + + def splitArray[T](ad: Array[Iterable[T]]): Any = + ad(0) match { + case _: HashMapCollision1[_, _] | _: HashSetCollision1[_] => null + } + + // without type ascription for the one in the body of the last flatmap of each alternative, type inference borks on the existentials + // def splitArray[T >: Nothing <: Any](ad: Array[Iterable[T]]): Any = { import OptionMatching._ + // runOrElse(ad.apply(0))(((x1: Iterable[T]) => ( + // or(((x4: Iterable[T]) => one(null)), + // guard(x1.isInstanceOf[Iterable[T] with Test.HashMapCollision1[_,_]], x1.asInstanceOf[Iterable[T] with Test.HashMapCollision1[_,_]]).flatMap(((x2: Iterable[T] with Test.HashMapCollision1[_,_]) => one(x2))), + // guard(x1.isInstanceOf[Test.HashSetCollision1[_]], x1.asInstanceOf[Iterable[T] with Test.HashSetCollision1[_]]).flatMap(((x3: Iterable[T] with Test.HashSetCollision1[_]) => one(x3)))): Option[Any]).orElse( + // (zero: Option[Any]))) + // ) + // } + +} + diff --git a/tests/pos/virtpatmat_exist3.scala b/tests/pos/virtpatmat_exist3.scala new file mode 100644 index 000000000..6a6d428b1 --- /dev/null +++ b/tests/pos/virtpatmat_exist3.scala @@ -0,0 +1,12 @@ +class ReferenceQueue[T] { + def wrapper(jref: ReferenceQueue[_]): ReferenceQueue[T] = + jref match { + case null => null + } + + // def wrapper(jref: ReferenceQueue[_]): ReferenceQueue[T] = OptionMatching.runOrElse(jref)(((x1: ReferenceQueue[_]) => + // (OptionMatching.guard(null.==(x1), x1.asInstanceOf[ReferenceQueue[_]]).flatMap(((x2: ReferenceQueue[_]) => + // OptionMatching.one(null))): Option[ReferenceQueue[T]]).orElse( + // (OptionMatching.zero: Option[ReferenceQueue[T]]))) + // ) +} diff --git a/tests/pos/virtpatmat_exist_uncurry.scala b/tests/pos/virtpatmat_exist_uncurry.scala new file mode 100644 index 000000000..727922b31 --- /dev/null +++ b/tests/pos/virtpatmat_exist_uncurry.scala @@ -0,0 +1,6 @@ +object Test { + trait Leaf[T] { + def collect[U](f: PartialFunction[Leaf[_], U]): List[U] + def leaves: List[Leaf[T]] = collect { case l: Leaf[T] => l } + } +} |