diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2015-12-26 22:12:57 +0100 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2015-12-26 22:12:57 +0100 |
commit | 2427f056447ab3f9a0ceaa001353eb0a4067e1bb (patch) | |
tree | b9013e390a217a2da5f46401164958adf44d48de /tests/pos | |
parent | c66613de7f32cfabbca765a96f1a3cc0ea2d5bcb (diff) | |
parent | e51b8845fb20fe3a4e1c655d4b72e2833906bbc2 (diff) | |
download | dotty-2427f056447ab3f9a0ceaa001353eb0a4067e1bb.tar.gz dotty-2427f056447ab3f9a0ceaa001353eb0a4067e1bb.tar.bz2 dotty-2427f056447ab3f9a0ceaa001353eb0a4067e1bb.zip |
Merge pull request #1006 from dotty-staging/more-tests
More tests
Diffstat (limited to 'tests/pos')
169 files changed, 3139 insertions, 3 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/hklub0.scala b/tests/pos/hklub0.scala new file mode 100644 index 000000000..36cd46332 --- /dev/null +++ b/tests/pos/hklub0.scala @@ -0,0 +1,5 @@ +object Test { + val a : scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq] = null + val b : scala.collection.generic.GenericCompanion[scala.collection.mutable.Seq] = null + List(a, b) // immutable.this.List.apply[scala.collection.generic.GenericCompanion[Seq]](Test.this.a, Test.this.b) +} 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/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/t3048.scala b/tests/pos/t3048.scala new file mode 100644 index 000000000..dc056ecba --- /dev/null +++ b/tests/pos/t3048.scala @@ -0,0 +1,8 @@ +class B +object C extends B + +class F[T <: B](cons: => T) +class F2[T <: B](cons: => T) extends F(cons) + +object D extends F2(C) // works +object E extends F2(new B {}) diff --git a/tests/pos/t3071.scala b/tests/pos/t3071.scala new file mode 100644 index 000000000..7e1443294 --- /dev/null +++ b/tests/pos/t3071.scala @@ -0,0 +1,7 @@ +class A (val i: Int) { + def copy (i: Int = this.i): A = new A(i) +} + +class B (val j: Int) extends A(1) { + override def copy (j: Int = this.j): B = new B(j) +} diff --git a/tests/pos/t3079.scala b/tests/pos/t3079.scala new file mode 100644 index 000000000..b7bd63190 --- /dev/null +++ b/tests/pos/t3079.scala @@ -0,0 +1,17 @@ +sealed trait Identity[A] { + val value: A +} + +trait Coerce[A, B] { + def unwrap: (A => B) +} + +object Coerce { + def IdentityCoerce[B] = new Coerce[Identity[B], B] { + // java.lang.Error: A in trait Identity cannot be instantiated from ?x$1.type + def unwrap = _.value + + // Providing the type of _ works around the problem. + //def unwrap = (_: Identity[B]).value + } +} diff --git a/tests/pos/t3136.scala b/tests/pos/t3136.scala new file mode 100644 index 000000000..239bd8f54 --- /dev/null +++ b/tests/pos/t3136.scala @@ -0,0 +1,19 @@ +class Type +class Symbol +case class PolyType(tps: List[Symbol], res: Type) extends Type +class OtherType extends Type + +// case class NullaryMethodType(tp: Type) extends Type + +object NullaryMethodType { + def apply(resTpe: Type): Type = PolyType(List(), resTpe) + def unapply(tp: Type): Option[(Type)] = None +} + +object Test { + def TEST(tp: Type): String = + tp match { + case PolyType(ps1, PolyType(ps2, res @ PolyType(a, b))) => "1" + tp // couldn't find a simpler version that still crashes + case NullaryMethodType(meh) => "2" + meh + } +} diff --git a/tests/pos/t3160.scala b/tests/pos/t3160.scala new file mode 100644 index 000000000..cc007dc01 --- /dev/null +++ b/tests/pos/t3160.scala @@ -0,0 +1,6 @@ +import scala.collection.mutable._ +class Node + +class A { + def f(x: Node): Node = ??? +} diff --git a/tests/pos/t3174b.scala b/tests/pos/t3174b.scala new file mode 100644 index 000000000..4df1bfe83 --- /dev/null +++ b/tests/pos/t3174b.scala @@ -0,0 +1,12 @@ +trait Foo[X] { def foo : Map[String,Foo[X]] } + +object Test { + def f[T]() : Foo[T] = { + class Anon extends Foo[T] { + var foo: Map[String, Foo[T]] = Map[String,Foo[T]]() + //def foo = Map[String,Foo[T]]() + //def foo_=(x: Map[String,Foo[T]]) {} + } + new Anon + } +} diff --git a/tests/pos/t318.scala b/tests/pos/t318.scala new file mode 100644 index 000000000..dbe0e0528 --- /dev/null +++ b/tests/pos/t318.scala @@ -0,0 +1,9 @@ +object Test { + def fun: Int = { + object o { + def a: Int = 1; + class C { def b: Int = a; } + } + 0 + } +} diff --git a/tests/pos/t3272.scala b/tests/pos/t3272.scala new file mode 100644 index 000000000..cf54d6a84 --- /dev/null +++ b/tests/pos/t3272.scala @@ -0,0 +1,8 @@ +trait A { + trait C[+T] { + protected[this] def f(t: T): Unit = {} + } + trait D[T] extends C[T] { + def g(t: T): Unit = { f(t) } + } +} 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/t3312.scala b/tests/pos/t3312.scala new file mode 100644 index 000000000..aef965d2e --- /dev/null +++ b/tests/pos/t3312.scala @@ -0,0 +1,17 @@ +trait Root { + def say: String +} + +trait A extends Root { + override def say: String = "bow" +} + +trait B extends Root { + override def say: String = "hi" +} + +object Foo extends A with B { + override def say: String = foo(super[A].say) + + def foo(p: => String): String = p +} diff --git a/tests/pos/t3371.scala b/tests/pos/t3371.scala new file mode 100644 index 000000000..897cd9de4 --- /dev/null +++ b/tests/pos/t3371.scala @@ -0,0 +1,9 @@ +// that compiles +class Test(myValue:String) { println(myValue) } + +// that compiles too +trait Other { val otherValue = "" } +class Test2(myValue:String) { self:Other => println(otherValue) } + +// that does not compile saying that myValue is not found +class Test3(myValue:String) { self:Other => println(myValue) } diff --git a/tests/pos/t3373.scala b/tests/pos/t3373.scala new file mode 100644 index 000000000..b6594fb6c --- /dev/null +++ b/tests/pos/t3373.scala @@ -0,0 +1,11 @@ +class Entry(time: Long) { + def getTime: Long = time +} + +object Test { + def extractTime(e: Entry) = e.getTime + + implicit val orderEntries: Ordering[Entry] = new Ordering[Entry] { + def compare(first: Entry, second: Entry) = extractTime(first) compare extractTime(second) + } +} diff --git a/tests/pos/t3374.scala b/tests/pos/t3374.scala new file mode 100644 index 000000000..c9bedcf69 --- /dev/null +++ b/tests/pos/t3374.scala @@ -0,0 +1,6 @@ +trait Parent { + type Test[A, H[B <: A]] +} +trait Sub extends Parent { + type Test[AS, HS[B <: AS]] = AS +} diff --git a/tests/pos/t3384.scala b/tests/pos/t3384.scala new file mode 100644 index 000000000..4d4a81d69 --- /dev/null +++ b/tests/pos/t3384.scala @@ -0,0 +1,14 @@ +package test + +package p { + class A(a: String = "") +} + +package object po { + type A = p.A +} + +import po._ +class C { + val a = new A() //p.A.init$default$1) +} diff --git a/tests/pos/t3420.scala b/tests/pos/t3420.scala new file mode 100644 index 000000000..0fc56ed67 --- /dev/null +++ b/tests/pos/t3420.scala @@ -0,0 +1,5 @@ +class C { + val cv = Map[Int, Int](1 -> 2) + lazy val cl = Map[Int, Int](1 -> 2) + def cd = Map[Int, Int](1 -> 2) +} diff --git a/tests/pos/t3430.scala b/tests/pos/t3430.scala new file mode 100644 index 000000000..f86d776bd --- /dev/null +++ b/tests/pos/t3430.scala @@ -0,0 +1,13 @@ +// package com.example + +object A { + def f1(f: String => Boolean) = f("a") + + def f2(): Boolean = + f1 { s1 => + f1 { s2 => + while (true) { } + true + } + } +} diff --git a/tests/pos/t3440.scala b/tests/pos/t3440.scala new file mode 100644 index 000000000..0e7ca6b70 --- /dev/null +++ b/tests/pos/t3440.scala @@ -0,0 +1,18 @@ +object test { + abstract class SampleFormat1 { + def readerFactory: Any + } + + case object Int8 extends SampleFormat1 { + def readerFactory = sys.error("") + } + case object Int16 extends SampleFormat1 { + def readerFactory = sys.error("") + } + + (new {}: Any) match { + case 8 => Int8 + case 16 => Int16 + case _ => sys.error("") + } +} diff --git a/tests/pos/t3452f.scala b/tests/pos/t3452f.scala new file mode 100644 index 000000000..efe25a62f --- /dev/null +++ b/tests/pos/t3452f.scala @@ -0,0 +1,10 @@ +class Base[Coll] { + trait Transformed[S] { + lazy val underlying: Coll = ??? + } +} + +class Derived extends Base[String] { + class C extends Transformed[Any] +} + 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/t348plus.scala b/tests/pos/t348plus.scala new file mode 100644 index 000000000..e61f7346f --- /dev/null +++ b/tests/pos/t348plus.scala @@ -0,0 +1,24 @@ +// bug #348 + +trait Foo { + type bar <: Bar; + abstract class Bar; + case class Baz(r:bar) extends Bar; + case object NoBar extends Bar; +} +object Test extends App { + object ConcreteFooBar extends Foo { // if moved to toplevel, it works + type bar = Bar; + } + def foo = { + import ConcreteFooBar._ ; + Baz( NoBar ) + } +} + +// bug #367 + +object Bla { + def foo(): Unit = (return null).equals(null); +} + diff --git a/tests/pos/t3495.scala b/tests/pos/t3495.scala new file mode 100644 index 000000000..8d5dff430 --- /dev/null +++ b/tests/pos/t3495.scala @@ -0,0 +1,2 @@ +class Foo { } + 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/t3528.scala b/tests/pos/t3528.scala new file mode 100644 index 000000000..ff49b3e92 --- /dev/null +++ b/tests/pos/t3528.scala @@ -0,0 +1,8 @@ +class A { + // 3528 - not fixed + // def f1 = List(List(1), Stream(1)) + // 3528 comments + def f2 = List(Set(1,2,3), List(1,2,3)) + // 2322 + def f3 = List(null: Range, null: List[Int]) +} 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/t3560.scala b/tests/pos/t3560.scala new file mode 100644 index 000000000..3cde9710d --- /dev/null +++ b/tests/pos/t3560.scala @@ -0,0 +1,2 @@ +trait Foo[X] { def foo : Map[String,Foo[X]] } +object T3560 { def f[T]() : Foo[T] = new Foo[T] { var foo = Map[String,Foo[T]]() } } 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/t3570.scala b/tests/pos/t3570.scala new file mode 100644 index 000000000..237391719 --- /dev/null +++ b/tests/pos/t3570.scala @@ -0,0 +1,7 @@ +class test { + object Break extends Throwable + def break = throw Break + def block(x: => Unit): Unit = { + try { x } catch { case e: Break.type => } + } +} diff --git a/tests/pos/t3578.scala b/tests/pos/t3578.scala new file mode 100644 index 000000000..2ce92a776 --- /dev/null +++ b/tests/pos/t3578.scala @@ -0,0 +1,30 @@ +object Test { + sealed abstract class JValue { + def ++(other: JValue) = { + def append(value1: JValue, value2: JValue): JValue = (value1, value2) match { + case (JNothing, x) => x + case (x, JNothing) => x + case (JObject(xs), x: JField) => JObject(xs ::: List(x)) + case (x: JField, JObject(xs)) => JObject(x :: xs) + case (JArray(xs), JArray(ys)) => JArray(xs ::: ys) + case (JArray(xs), v: JValue) => JArray(xs ::: List(v)) + case (v: JValue, JArray(xs)) => JArray(v :: xs) + case (f1: JField, f2: JField) => JObject(f1 :: f2 :: Nil) + case (JField(n, v1), v2: JValue) => JField(n, append(v1, v2)) + case (x, y) => JArray(x :: y :: Nil) + } + append(this, other) + } + } + + case object JNothing extends JValue + case object JNull extends JValue + case class JString(s: String) extends JValue + case class JDouble(num: Double) extends JValue + case class JInt(num: BigInt) extends JValue + case class JBool(value: Boolean) extends JValue + case class JField(name: String, value: JValue) extends JValue + case class JObject(obj: List[JField]) extends JValue + case class JArray(arr: List[JValue]) extends JValue +} + diff --git a/tests/pos/t3582.scala b/tests/pos/t3582.scala new file mode 100644 index 000000000..d13d69775 --- /dev/null +++ b/tests/pos/t3582.scala @@ -0,0 +1,12 @@ +trait C[A] +object Test { + def ImplicitParamCA[CC[A], A](implicit ev: C[A]): Unit = {implicitly[C[A]]} // must use this exact syntax... + // error: could not find implicit value for parameter e: C[A] +} +// [[syntax trees at end of typer]] +// abstract trait C#5[A#9116 >: Nothing#5832 <: Any#52] extends scala#33.AnyRef#2780; +// final object Test#15 extends java.lang.Object#2485 with ScalaObject#1913 { +// def ImplicitParamCA#9123[CC#9124[A#10858 >: Nothing#5832 <: Any#52] >: [A#10858]Nothing#5832 <: [A#10858]Any#52, +// A#9125 >: Nothing#5832 <: Any#52](implicit ev#10856: C#5[A#9127]): Unit#3818 +// = scala#34.this.Predef#1683.implicitly#8816[C#5[A#10858]]() +// } 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/t359.scala b/tests/pos/t359.scala new file mode 100644 index 000000000..11233c3ba --- /dev/null +++ b/tests/pos/t359.scala @@ -0,0 +1,28 @@ +object Bug359 { + class C; + def f1(xs: List[C]): C = { + g { + xs => + if (false) { + f1(xs) + } else { + val a: C = null; + val b: C = null; + if (xs.isEmpty) a else b + } + } + } + def f2(xs: List[C]): C = { + g { + xs => + if (false) { + val a: C = null; + val b: C = null; + if (xs.isEmpty) a else b + } else { + f2(xs); + } + } + } + private def g(op: List[C] => C): C = null; +} 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/t361.scala b/tests/pos/t361.scala new file mode 100644 index 000000000..1d19ecb52 --- /dev/null +++ b/tests/pos/t361.scala @@ -0,0 +1,16 @@ +class Bug361Global extends Bug361Trees + +abstract class Bug361Trees { self: Bug361Global => + + abstract class Tree { + var pos: Int = 0 + } + + object posAssigner { + def atPos[T <: Tree](pos: Int, tree: T): T = { + tree.pos = pos; tree + } + } + + def atPos[T <: Tree](pos: Int)(tree: T): T = posAssigner.atPos(pos, tree) +} 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/t3636.scala b/tests/pos/t3636.scala new file mode 100644 index 000000000..cd224a32f --- /dev/null +++ b/tests/pos/t3636.scala @@ -0,0 +1,49 @@ +class CTxnLocal[ T ] { + def set( x: T )( implicit t: Txn ): Unit = {} + def get( implicit t: Txn ) : T = null.asInstanceOf[ T ] + def initialValue( t: Txn ) : T = null.asInstanceOf[ T ] +} + +trait Txn + +trait ProcTxn { + def ccstm: Txn +} + +trait TxnLocal[ @specialized T ] { + def apply()( implicit tx: ProcTxn ) : T + def set( v: T )( implicit tx: ProcTxn ) : Unit + def swap( v: T )( implicit tx: ProcTxn ) : T + def transform( f: T => T )( implicit tx: ProcTxn ) : Unit +} + +object TxnLocal { + def apply[ @specialized T ] : TxnLocal[ T ] = new Impl( new CTxnLocal[ T ]) + def apply[ @specialized T ]( initValue: => T ) : TxnLocal[ T ] = new Impl( new CTxnLocal[ T ] { + override def initialValue( tx: Txn ): T = initValue + }) + + private class Impl[ T ]( c: CTxnLocal[ T ]) extends TxnLocal[ T ] { + def apply()( implicit tx: ProcTxn ) : T = c.get( tx.ccstm ) + def set( v: T )( implicit tx: ProcTxn ) : Unit = c.set( v )( tx.ccstm ) + def swap( v: T )( implicit tx: ProcTxn ) : T = { + // currently not implemented in CTxnLocal + val oldV = apply + set( v ) + oldV + } + def transform( f: T => T )( implicit tx: ProcTxn ): Unit = { + set( f( apply )) + } + } +} + + +object Transition { + private val currentRef = TxnLocal[ Transition ]( Instant ) + def current( implicit tx: ProcTxn ) : Transition = currentRef() +} + +sealed abstract class Transition +case object Instant extends Transition + diff --git a/tests/pos/t3670.scala b/tests/pos/t3670.scala new file mode 100644 index 000000000..4eb7cebbc --- /dev/null +++ b/tests/pos/t3670.scala @@ -0,0 +1,43 @@ +class A { + val n = { + val z = { + lazy val bb = 1 + bb + } + val a = { + lazy val cc = 2 + cc + } + lazy val b = { + lazy val dd = 3 + dd + } + z + } +} + +class B { + locally { + lazy val ms = "as" + ms + } +} + +class C { + val things = List("things") + if (things.size < 100) { + lazy val msg = "foo" + msg + } +} + +class D { + val things = List("things") + if (things.size < 100) { + if (things.size > 10) { + lazy val msg = "foo" + msg + } + } +} + diff --git a/tests/pos/t3671.scala b/tests/pos/t3671.scala new file mode 100644 index 000000000..afb3a539d --- /dev/null +++ b/tests/pos/t3671.scala @@ -0,0 +1,7 @@ +object Crash { + def crash(value: Int): Unit = + value match { + case java.lang.Integer.MAX_VALUE => println("MAX_VALUE") + case java.lang.Integer.MIN_VALUE => println("MIN_VALUE") + } +} diff --git a/tests/pos/t3672.scala b/tests/pos/t3672.scala new file mode 100644 index 000000000..b2752ce21 --- /dev/null +++ b/tests/pos/t3672.scala @@ -0,0 +1,4 @@ +object Test { + def foo(f: Int => Int) = () ; foo { implicit x : Int => x + 1 } + def bar(f: Int => Int) = () ; foo { x : Int => x + 1 } +} diff --git a/tests/pos/t3676.scala b/tests/pos/t3676.scala new file mode 100644 index 000000000..60c0ceaec --- /dev/null +++ b/tests/pos/t3676.scala @@ -0,0 +1,5 @@ +trait SeqLike[+Repr] +trait Seq extends SeqLike[Seq] + +trait MySeq extends Seq with SeqLike[MySub] +trait MySub extends MySeq 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/t372.scala b/tests/pos/t372.scala new file mode 100644 index 000000000..9ce5b9ab7 --- /dev/null +++ b/tests/pos/t372.scala @@ -0,0 +1,2 @@ +class Bug372Names; +class Bug372Symbols { self: Bug372Symbols with Bug372Names => } diff --git a/tests/pos/t3731.scala b/tests/pos/t3731.scala new file mode 100644 index 000000000..7a3cbec0f --- /dev/null +++ b/tests/pos/t3731.scala @@ -0,0 +1,13 @@ +object Test{ + trait ZW[S]{type T} + def ZipWith[S, M <: ZW[S]]: M#T = sys.error("ZW") + + // meh must be parameterised to force an asSeenFrom that + // duplicates the refinement in the TR's pre without updating its sym + def meh[A] = ZipWith[A, ZW[A]{type T=Stream[A]}] + + meh[Int]: Stream[Int] +} +// debugging output in coevolveSym should say: +// coevolved type T#11029 : Stream#3234[A#9228] to type T#11277 : Stream#3234[A#9227] +// with Test.ZW#9219[A#9228]{type T#11029 = Stream#3234[A#9228]} -> Test.ZW#9219[A#9227]{type T#11277 = Stream#3234[A#9227]} diff --git a/tests/pos/t374.scala b/tests/pos/t374.scala new file mode 100644 index 000000000..fb9c0b402 --- /dev/null +++ b/tests/pos/t374.scala @@ -0,0 +1,21 @@ +object tokens extends Enumeration { + type Token = Value; + val BAD = Value("<bad>"); + val IDENT = Value("ident"); + val NAME = Value("name"); +} + +object test extends AnyRef with App { + import tokens._; + + val reserved = new scala.collection.mutable.HashMap[String, Token](); + + if (true) { + reserved.get("a") match { + case None => IDENT + case Some(tk) => tk + } + } + else + BAD +} diff --git a/tests/pos/t3774.scala b/tests/pos/t3774.scala new file mode 100644 index 000000000..2869925b0 --- /dev/null +++ b/tests/pos/t3774.scala @@ -0,0 +1,5 @@ +// This used to hang the lub process. Now it rejects the file. This is still not correct, +// but we can solve this only after a redesign of lub a la dot. +object Hang { + Map[(Int,Int),List[Int]]() ++ (for(x <- 0 to 1 ; y <- 0 to 1) yield {(x,y)-> (0 to 1)}) +} 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/t3792.scala b/tests/pos/t3792.scala new file mode 100644 index 000000000..364d46317 --- /dev/null +++ b/tests/pos/t3792.scala @@ -0,0 +1,4 @@ +object Test { + type Hui = Nil.type + val n: Hui = Nil +} diff --git a/tests/pos/t3808.scala b/tests/pos/t3808.scala new file mode 100644 index 000000000..ec95fed4d --- /dev/null +++ b/tests/pos/t3808.scala @@ -0,0 +1,11 @@ +object Test { + def meh: Unit = { + trait TC[I] + implicit val tci: TC[Int] = new TC[Int]{} + + def baz[J : TC] : String = "meh" + + baz + // () // commenting or uncommenting this line should not affect compilation (visibly) + } +} diff --git a/tests/pos/t3833.scala b/tests/pos/t3833.scala new file mode 100644 index 000000000..2df658df1 --- /dev/null +++ b/tests/pos/t3833.scala @@ -0,0 +1,26 @@ +object Main { + def mkArray[T <: A](atype: Int) :T#AType = { + (atype match { + case 1 => + new Array[Int](10) + // Decompiled code: return (Object[])new int[10]; + case 2 => + new Array[Float](10) + }).asInstanceOf[T#AType] + } + + def main(args: Array[String]): Unit = { + println(mkArray[I](1)) + //java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object; + } +} + +trait A { + type AType <: AnyRef +} +trait I extends A { + type AType = Array[Int] +} +trait F extends A { + type AType = Array[Float] +} diff --git a/tests/pos/t3836.scala b/tests/pos/t3836.scala new file mode 100644 index 000000000..840f17116 --- /dev/null +++ b/tests/pos/t3836.scala @@ -0,0 +1,14 @@ +package foo + +package object bar { + type IOException = java.io.IOException +} + +package baz { + import java.io._ + import foo.bar._ + + object Test { + def f = new IOException + } +} diff --git a/tests/pos/t3837.scala b/tests/pos/t3837.scala new file mode 100644 index 000000000..bcaf63cc8 --- /dev/null +++ b/tests/pos/t3837.scala @@ -0,0 +1,10 @@ +class BipClass { } +trait BipTrait { + self: BipClass => + + private[this] def foo() = 5 + def bar() = this.foo() +} +// error: value foo is not a member of BipTrait with BipClass +// def bar() = this.foo() +// ^ 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/t3861.scala b/tests/pos/t3861.scala new file mode 100644 index 000000000..5ebe02520 --- /dev/null +++ b/tests/pos/t3861.scala @@ -0,0 +1,2 @@ +trait Y +abstract class X(x: Int) { self: Y => x } diff --git a/tests/pos/t3866.scala b/tests/pos/t3866.scala new file mode 100644 index 000000000..f1f64edb9 --- /dev/null +++ b/tests/pos/t3866.scala @@ -0,0 +1,17 @@ +abstract class ImplicitRepeated { + trait T[+A, +B] + trait X + + def f[N, R <: List[_]](elems: T[N, R]*): Unit // alternative a) + def f[N, R <: List[_]](props: String, elems: T[N, R]*): Unit // alternative b) + + // the following implicit causes "cannot be applied" errors + implicit def xToRight(r: X): T[Nothing, X] = null + implicit def anyToN[N](x: N): T[N, Nothing] = null + + + f("A", 1, 2) // should be implicitly resolved to alternative b) + f( 1, 2 ) // should be implicitly resolved to alternative a) + // ImplicitRepeated.this.f[Int, Nothing]("A", ImplicitRepeated.this.anyToN[Int](1), ImplicitRepeated.this.anyToN[Int](2)); + // ImplicitRepeated.this.f[Int, Nothing](ImplicitRepeated.this.anyToN[Int](1), ImplicitRepeated.this.anyToN[Int](2)) +} 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/t3883.scala b/tests/pos/t3883.scala new file mode 100644 index 000000000..1b62c0c6d --- /dev/null +++ b/tests/pos/t3883.scala @@ -0,0 +1,15 @@ +// need to test both orders +object A1 { + implicit def i: Equiv[Boolean] = sys.error("") + implicit def div[T, A](implicit f: T => A, eq: Equiv[A]): Equiv[T] = sys.error("") + + implicitly[Equiv[Boolean]] +} + +object A2 { + implicit def div[T, A](implicit f: T => A, eq: Equiv[A]): Equiv[T] = sys.error("") + implicit def i: Equiv[Boolean] = sys.error("") + + implicitly[Equiv[Boolean]] +} + diff --git a/tests/pos/t389.scala b/tests/pos/t389.scala new file mode 100644 index 000000000..535bd4de8 --- /dev/null +++ b/tests/pos/t389.scala @@ -0,0 +1,7 @@ +object Test { + def a = 'a + def b = 'B + def c = '+ + //def d = '`\n` //error: unclosed character literal + def e = '\u0041 +} diff --git a/tests/pos/t3890.scala b/tests/pos/t3890.scala new file mode 100644 index 000000000..0c5f5dfe6 --- /dev/null +++ b/tests/pos/t3890.scala @@ -0,0 +1,4 @@ +object Test { + def g[S, T <: S](s: S)(t: T): Unit = println("") + g("a")("a") // error: inferred type arguments [java.lang.String] do not conform to method g's type parameter bounds [T <: S] +} diff --git a/tests/pos/t3898.scala b/tests/pos/t3898.scala new file mode 100644 index 000000000..ab47bbd87 --- /dev/null +++ b/tests/pos/t3898.scala @@ -0,0 +1,6 @@ +trait Atomic[@specialized(Boolean) T] { + def x: T + + def f(fn: T => T): Boolean = f(fn(x), true) + def f[R](a: T, b: R): R = b +} diff --git a/tests/pos/t3924.scala b/tests/pos/t3924.scala new file mode 100644 index 000000000..b11b67c56 --- /dev/null +++ b/tests/pos/t3924.scala @@ -0,0 +1,6 @@ +object Test { + class Hoe extends Serializable { + def add(a: java.io.Serializable): Unit = println(a) + def someMethod(): Unit = { add(this) } + } +} diff --git a/tests/pos/t3927.scala b/tests/pos/t3927.scala new file mode 100644 index 000000000..5e0d581d4 --- /dev/null +++ b/tests/pos/t3927.scala @@ -0,0 +1,6 @@ +object A { + def x: Unit = { + implicit lazy val e: Equiv[Int] = sys.error("") + implicitly[Equiv[Int]] + } +} 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/t397.scala b/tests/pos/t397.scala new file mode 100644 index 000000000..87be2987a --- /dev/null +++ b/tests/pos/t397.scala @@ -0,0 +1,16 @@ +abstract class Root { + + abstract class Edge { + type V; + def source: V; + } + + abstract class Graph { + type W; + type E <: Edge{type V = W}; + def edge: E; + } + + val g: Graph{type W = Int}; + val x: Int = g.edge.source; +} diff --git a/tests/pos/t3972.scala b/tests/pos/t3972.scala new file mode 100644 index 000000000..65ef43f84 --- /dev/null +++ b/tests/pos/t3972.scala @@ -0,0 +1,11 @@ +object CompilerCrash { + def main(args: Array[String]): Unit = { + args match { + case Array("a", a : _*) => { } // The code compiles fine if this line is commented out or "@ _*" is deleted or this line is swapped for the next line + case Array("b") => { } // The code compiles fine if this line is commented out + case Array("c", c) => { + 0 // The code compiles fine if this line is commented out + } + } + } +} 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/t4176b.scala b/tests/pos/t4176b.scala new file mode 100644 index 000000000..eebb5dda5 --- /dev/null +++ b/tests/pos/t4176b.scala @@ -0,0 +1,5 @@ +object Test { + def foo(a1: String*) = a1 +// val fooEta = foo _ + (foo: Seq[String] => Seq[String]) +} 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/t4579.scala b/tests/pos/t4579.scala new file mode 100644 index 000000000..8ce657eff --- /dev/null +++ b/tests/pos/t4579.scala @@ -0,0 +1,518 @@ +//############################################################################ +// Lisp interpreter (revived as an optimizer test.) +//############################################################################ + +//############################################################################ +// Lisp Scanner + +class LispTokenizer(s: String) extends Iterator[String] { + private var i = 0; + private def isDelimiter(ch: Char) = ch <= ' ' || ch == '(' || ch == ')' + def hasNext: Boolean = { + while (i < s.length() && s.charAt(i) <= ' ') i += 1 + i < s.length() + } + def next: String = + if (hasNext) { + val start = i + if (isDelimiter(s charAt i)) i += 1 + else + do i = i + 1 + while (!isDelimiter(s charAt i)) + s.substring(start, i) + } else sys.error("premature end of string") +} + +//############################################################################ +// Lisp Interface + +trait Lisp { + type Data + + def string2lisp(s: String): Data + def lisp2string(s: Data): String + + def evaluate(d: Data): Data + // !!! def evaluate(s: String): Data = evaluate(string2lisp(s)) + def evaluate(s: String): Data +} + +//############################################################################ +// Lisp Implementation Using Case Classes + +object LispCaseClasses extends Lisp { + + import List.range + + trait Data { + def elemsToString(): String = toString(); + } + case class CONS(car: Data, cdr: Data) extends Data { + override def toString() = "(" + elemsToString() + ")"; + override def elemsToString() = car.toString() + (cdr match { + case NIL() => "" + case _ => " " + cdr.elemsToString(); + }) + } + case class NIL() extends Data { // !!! use case object + override def toString() = "()"; + } + case class SYM(name: String) extends Data { + override def toString() = name; + } + case class NUM(x: Int) extends Data { + override def toString() = x.toString(); + } + case class STR(x: String) extends Data { + override def toString() = "\"" + x + "\""; + } + case class FUN(f: List[Data] => Data) extends Data { + override def toString() = "<fn>"; + } + + def list(): Data = + NIL(); + def list(x0: Data): Data = + CONS(x0, NIL()); + def list(x0: Data, x1: Data): Data = + CONS(x0, list(x1)); + def list(x0: Data, x1: Data, x2: Data): Data = + CONS(x0, list(x1, x2)); + def list(x0: Data, x1: Data, x2: Data, x3: Data): Data = + CONS(x0, list(x1, x2, x3)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data): Data = + CONS(x0, list(x1, x2, x3, x4)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data, x5: Data): Data = + CONS(x0, list(x1, x2, x3, x4, x5)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data, x5: Data, + x6: Data): Data = + CONS(x0, list(x1, x2, x3, x4, x5, x6)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data, x5: Data, + x6: Data, x7: Data): Data = + CONS(x0, list(x1, x2, x3, x4, x5, x6, x7)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data, x5: Data, + x6: Data, x7: Data, x8: Data): Data = + CONS(x0, list(x1, x2, x3, x4, x5, x6, x7, x8)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data, x5: Data, + x6: Data, x7: Data, x8: Data, x9: Data): Data = + CONS(x0, list(x1, x2, x3, x4, x5, x6, x7, x8, x9)); + + var curexp: Data = null + var trace: Boolean = false + var indent: Int = 0 + + def lispError[a](msg: String): a = + sys.error("error: " + msg + "\n" + curexp); + + trait Environment { + def lookup(n: String): Data; + def extendRec(name: String, expr: Environment => Data) = + new Environment { + def lookup(n: String): Data = + if (n == name) expr(this) else Environment.this.lookup(n); + } + def extend(name: String, v: Data) = extendRec(name, (env1 => v)); + } + val EmptyEnvironment = new Environment { + def lookup(n: String): Data = lispError("undefined: " + n); + } + + def toList(x: Data): List[Data] = x match { + case NIL() => List() + case CONS(y, ys) => y :: toList(ys) + case _ => lispError("malformed list: " + x); + } + + def toBoolean(x: Data) = x match { + case NUM(0) => false + case _ => true + } + + def normalize(x: Data): Data = x match { + case CONS(SYM("def"), + CONS(CONS(SYM(name), args), CONS(body, CONS(expr, NIL())))) => + normalize(list(SYM("def"), + SYM(name), list(SYM("lambda"), args, body), expr)) + case CONS(SYM("cond"), CONS(CONS(SYM("else"), CONS(expr, NIL())),NIL())) => + normalize(expr) + case CONS(SYM("cond"), CONS(CONS(test, CONS(expr, NIL())), rest)) => + normalize(list(SYM("if"), test, expr, CONS(SYM("cond"), rest))) + case CONS(h, t) => CONS(normalize(h), normalize(t)) + case _ => x + } + + def eval(x: Data, env: Environment): Data = { + val prevexp = curexp; + curexp = x; + if (trace) { + for (x <- range(1, indent)) Console.print(" "); + Console.println("===> " + x); + indent = indent + 1; + } + val result = eval1(x, env); + if (trace) { + indent = indent - 1; + for (x <- range(1, indent)) Console.print(" "); + Console.println("<=== " + result); + } + curexp = prevexp; + result + } + + def eval1(x: Data, env: Environment): Data = x match { + case SYM(name) => + env lookup name + case CONS(SYM("def"), CONS(SYM(name), CONS(y, CONS(z, NIL())))) => + eval(z, env.extendRec(name, (env1 => eval(y, env1)))) + case CONS(SYM("val"), CONS(SYM(name), CONS(y, CONS(z, NIL())))) => + eval(z, env.extend(name, eval(y, env))) + case CONS(SYM("lambda"), CONS(params, CONS(y, NIL()))) => + mkLambda(params, y, env) + case CONS(SYM("if"), CONS(c, CONS(t, CONS(e, NIL())))) => + if (toBoolean(eval(c, env))) eval(t, env) else eval(e, env) + case CONS(SYM("quote"), CONS(x, NIL())) => + x + case CONS(y, xs) => + apply(eval(y, env), toList(xs) map (x => eval(x, env))) + case NUM(_) => x + case STR(_) => x + case FUN(_) => x + case _ => + lispError("illegal term") + } + + def apply(fn: Data, args: List[Data]): Data = fn match { + case FUN(f) => f(args); + case _ => lispError("application of non-function: " + fn); + } + + def mkLambda(params: Data, expr: Data, env: Environment): Data = { + + def extendEnv(env: Environment, + ps: List[String], args: List[Data]): Environment = + (ps, args) match { + case (List(), List()) => + env + case (p :: ps1, arg :: args1) => + extendEnv(env.extend(p, arg), ps1, args1) + case _ => + lispError("wrong number of arguments") + } + + val ps: List[String] = toList(params) map { + case SYM(name) => name + case _ => sys.error("illegal parameter list"); + } + + FUN(args => eval(expr, extendEnv(env, ps, args))) + } + + val globalEnv = EmptyEnvironment + .extend("=", FUN({ + case List(NUM(arg1),NUM(arg2)) => NUM(if (arg1 == arg2) 1 else 0) + case List(STR(arg1),STR(arg2)) => NUM(if (arg1 == arg2) 1 else 0)})) + .extend("+", FUN({ + case List(NUM(arg1),NUM(arg2)) => NUM(arg1 + arg2) + case List(STR(arg1),STR(arg2)) => STR(arg1 + arg2)})) + .extend("-", FUN({ + case List(NUM(arg1),NUM(arg2)) => NUM(arg1 - arg2)})) + .extend("*", FUN({ + case List(NUM(arg1),NUM(arg2)) => NUM(arg1 * arg2)})) + .extend("/", FUN({ + case List(NUM(arg1),NUM(arg2)) => NUM(arg1 / arg2)})) + .extend("car", FUN({ + case List(CONS(x, xs)) => x})) + .extend("cdr", FUN({ + case List(CONS(x, xs)) => xs})) + .extend("null?", FUN({ + case List(NIL()) => NUM(1) + case _ => NUM(0)})) + .extend("cons", FUN({ + case List(x, y) => CONS(x, y)})); + + def evaluate(x: Data): Data = eval(normalize(x), globalEnv); + def evaluate(s: String): Data = evaluate(string2lisp(s)); + + def string2lisp(s: String): Data = { + val it = new LispTokenizer(s); + def parse(token: String): Data = { + if (token == "(") parseList + else if (token == ")") sys.error("unbalanced parentheses") + else if ('0' <= token.charAt(0) && token.charAt(0) <= '9') + NUM(token.toInt) + else if (token.charAt(0) == '\"' && token.charAt(token.length()-1)=='\"') + STR(token.substring(1,token.length() - 1)) + else SYM(token) + } + def parseList: Data = { + val token = it.next; + if (token == ")") NIL() else CONS(parse(token), parseList) + } + parse(it.next) + } + + def lisp2string(d: Data): String = d.toString(); +} + +//############################################################################ +// Lisp Implementation Using Any + +object LispAny extends Lisp { + + import List._; + + type Data = Any; + + case class Lambda(f: List[Data] => Data); + + var curexp: Data = null; + var trace: Boolean = false; + var indent: Int = 0; + + def lispError[a](msg: String): a = + sys.error("error: " + msg + "\n" + curexp); + + trait Environment { + def lookup(n: String): Data; + def extendRec(name: String, expr: Environment => Data) = + new Environment { + def lookup(n: String): Data = + if (n == name) expr(this) else Environment.this.lookup(n); + } + def extend(name: String, v: Data) = extendRec(name, (env1 => v)); + } + val EmptyEnvironment = new Environment { + def lookup(n: String): Data = lispError("undefined: " + n); + } + + def asList(x: Data): List[Data] = x match { + case y: List[_] => y + case _ => lispError("malformed list: " + x) + } + + def asInt(x: Data): Int = x match { + case y: Int => y + case _ => lispError("not an integer: " + x) + } + + def asString(x: Data): String = x match { + case y: String => y + case _ => lispError("not a string: " + x) + } + + def asBoolean(x: Data): Boolean = x != 0 + + def normalize(x: Data): Data = x match { + case 'and :: x :: y :: Nil => + normalize('if :: x :: y :: 0 :: Nil) + case 'or :: x :: y :: Nil => + normalize('if :: x :: 1 :: y :: Nil) + case 'def :: (name :: args) :: body :: expr :: Nil => + normalize('def :: name :: ('lambda :: args :: body :: Nil) :: expr :: Nil) + case 'cond :: ('else :: expr :: Nil) :: rest => + normalize(expr); + case 'cond :: (test :: expr :: Nil) :: rest => + normalize('if :: test :: expr :: ('cond :: rest) :: Nil) + case 'cond :: 'else :: expr :: Nil => + normalize(expr) + case h :: t => + normalize(h) :: asList(normalize(t)) + case _ => + x + } + + def eval(x: Data, env: Environment): Data = { + val prevexp = curexp; + curexp = x; + if (trace) { + for (x <- range(1, indent)) Console.print(" "); + Console.println("===> " + x); + indent += 1; + } + val result = eval1(x, env); + if (trace) { + indent -= 1; + for (x <- range(1, indent)) Console.print(" "); + Console.println("<=== " + result); + } + curexp = prevexp; + result + } + + def eval1(x: Data, env: Environment): Data = x match { + case Symbol(name) => + env lookup name + case 'def :: Symbol(name) :: y :: z :: Nil => + eval(z, env.extendRec(name, (env1 => eval(y, env1)))) + case 'val :: Symbol(name) :: y :: z :: Nil => + eval(z, env.extend(name, eval(y, env))) + case 'lambda :: params :: y :: Nil => + mkLambda(params, y, env) + case 'if :: c :: y :: z :: Nil => + if (asBoolean(eval(c, env))) eval(y, env) else eval(z, env) + case 'quote :: y :: Nil => + y + case y :: z => + apply(eval(y, env), z map (x => eval(x, env))) + case Lambda(_) => x + case y: String => x + case y: Int => x + case y => lispError("illegal term") + } + + def lisp2string(x: Data): String = x match { + case Symbol(name) => name + case Nil => "()" + case y :: ys => + def list2string(xs: List[Data]): String = xs match { + case List() => "" + case y :: ys => " " + lisp2string(y) + list2string(ys) + } + "(" + lisp2string(y) + list2string(ys) + ")" + case _ => if (x.isInstanceOf[String]) "\"" + x + "\""; else x.toString() + } + + def apply(fn: Data, args: List[Data]): Data = fn match { + case Lambda(f) => f(args); + case _ => lispError("application of non-function: " + fn + " to " + args); + } + + def mkLambda(params: Data, expr: Data, env: Environment): Data = { + + def extendEnv(env: Environment, + ps: List[String], args: List[Data]): Environment = + (ps, args) match { + case (List(), List()) => + env + case (p :: ps1, arg :: args1) => + extendEnv(env.extend(p, arg), ps1, args1) + case _ => + lispError("wrong number of arguments") + } + + val ps: List[String] = asList(params) map { + case Symbol(name) => name + case _ => sys.error("illegal parameter list"); + } + + Lambda(args => eval(expr, extendEnv(env, ps, args))) + } + + val globalEnv = EmptyEnvironment + .extend("=", Lambda{ + case List(arg1, arg2) => if (arg1 == arg2) 1 else 0}) + .extend("+", Lambda{ + case List(arg1: Int, arg2: Int) => arg1 + arg2 + case List(arg1: String, arg2: String) => arg1 + arg2}) + .extend("-", Lambda{ + case List(arg1: Int, arg2: Int) => arg1 - arg2}) + .extend("*", Lambda{ + case List(arg1: Int, arg2: Int) => arg1 * arg2}) + .extend("/", Lambda{ + case List(arg1: Int, arg2: Int) => arg1 / arg2}) + .extend("nil", Nil) + .extend("cons", Lambda{ + case List(arg1, arg2) => arg1 :: asList(arg2)}) + .extend("car", Lambda{ + case List(x :: xs) => x}) + .extend("cdr", Lambda{ + case List(x :: xs) => xs}) + .extend("null?", Lambda{ + case List(Nil) => 1 + case _ => 0}); + + def evaluate(x: Data): Data = eval(normalize(x), globalEnv); + def evaluate(s: String): Data = evaluate(string2lisp(s)); + + def string2lisp(s: String): Data = { + val it = new LispTokenizer(s); + def parse(token: String): Data = { + if (token == "(") parseList + else if (token == ")") sys.error("unbalanced parentheses") + //else if (Character.isDigit(token.charAt(0))) + else if (token.charAt(0).isDigit) + token.toInt + else if (token.charAt(0) == '\"' && token.charAt(token.length()-1)=='\"') + token.substring(1,token.length() - 1) + else Symbol(token) + } + def parseList: List[Data] = { + val token = it.next; + if (token == ")") Nil else parse(token) :: parseList + } + parse(it.next) + } +} + +//############################################################################ +// List User + +class LispUser(lisp: Lisp) { + + import lisp._; + + def evaluate(s: String) = lisp2string(lisp.evaluate(s)); + + def run = { + + Console.println(string2lisp("(lambda (x) (+ (* x x) 1))").asInstanceOf[AnyRef]); + Console.println(lisp2string(string2lisp("(lambda (x) (+ (* x x) 1))"))); + Console.println; + + Console.println("( '(1 2 3)) = " + evaluate(" (quote(1 2 3))")); + Console.println("(car '(1 2 3)) = " + evaluate("(car (quote(1 2 3)))")); + Console.println("(cdr '(1 2 3)) = " + evaluate("(cdr (quote(1 2 3)))")); + Console.println("(null? '(2 3)) = " + evaluate("(null? (quote(2 3)))")); + Console.println("(null? '()) = " + evaluate("(null? (quote()))")); + Console.println; + + Console.println("faculty(10) = " + evaluate( + "(def (faculty n) " + + "(if (= n 0) " + + "1 " + + "(* n (faculty (- n 1)))) " + + "(faculty 10))")); + Console.println("faculty(10) = " + evaluate( + "(def (faculty n) " + + "(cond " + + "((= n 0) 1) " + + "(else (* n (faculty (- n 1))))) " + + "(faculty 10))")); + Console.println("foobar = " + evaluate( + "(def (foo n) " + + "(cond " + + "((= n 0) \"a\")" + + "((= n 1) \"b\")" + + "((= (/ n 2) 1) " + + "(cond " + + "((= n 2) \"c\")" + + "(else \"d\")))" + + "(else " + + "(def (bar m) " + + "(cond " + + "((= m 0) \"e\")" + + "((= m 1) \"f\")" + + "(else \"z\"))" + + "(bar (- n 4)))))" + + "(val nil (quote ())" + + "(val v1 (foo 0) " + + "(val v2 (+ (foo 1) (foo 2)) " + + "(val v3 (+ (+ (foo 3) (foo 4)) (foo 5)) " + + "(val v4 (foo 6) " + + "(cons v1 (cons v2 (cons v3 (cons v4 nil))))))))))")); + Console.println; + } +} + +//############################################################################ +// Main + +object Test { + def main(args: Array[String]): Unit = { + new LispUser(LispCaseClasses).run; + new LispUser(LispAny).run; + () + } +} + +//############################################################################ 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/t4760.scala b/tests/pos/t4760.scala new file mode 100644 index 000000000..039f08368 --- /dev/null +++ b/tests/pos/t4760.scala @@ -0,0 +1,35 @@ + +class Test { + // parses + def f1 = { + import scala._; + } + // b.scala:7: error: ';' expected but '}' found. + // } + // ^ + // one error found + def f2 = { + import scala._ + } + def f2b = { + import scala.collection.mutable.{ Map => MMap } + } + def f(): Unit = { + locally { + import scala.util.Properties.lineSeparator + } + } + + // parses + def f3 = { + import scala._ + 5 + } + locally { (x: Int) => + import scala.util._ + } + 1 match { + case 1 => import scala.concurrent._ + } +} + 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/t6335.scala b/tests/pos/t6335.scala new file mode 100644 index 000000000..eb052db19 --- /dev/null +++ b/tests/pos/t6335.scala @@ -0,0 +1,25 @@ +object E extends Z { + def X = 3 + implicit class X(val i: Int) { + def xx = i + } + + def Y(a: Any) = 0 + object Y + implicit class Y(val i: String) { def yy = i } + + implicit class Z(val i: Boolean) { def zz = i } +} + +trait Z { + def Z = 0 +} + +object Test { + import E._ + 0.xx + + "".yy + + true.zz +} 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 } + } +} |