diff options
author | Dmitry Petrashko <dark@d-d.me> | 2014-05-20 16:04:39 +0200 |
---|---|---|
committer | Dmitry Petrashko <dark@d-d.me> | 2014-05-20 16:04:39 +0200 |
commit | deea15e9b0c56b7f55f5e40665d5e00baef4f028 (patch) | |
tree | bfb268ddfb648c4e3bba5081494f6bc0f506fe20 /tests/pos | |
parent | 8a4186ff782efefb98686aa35bf7f5dd1418210d (diff) | |
parent | 6b090d1204b5ee553cf9f04b83e48904dcd88183 (diff) | |
download | dotty-deea15e9b0c56b7f55f5e40665d5e00baef4f028.tar.gz dotty-deea15e9b0c56b7f55f5e40665d5e00baef4f028.tar.bz2 dotty-deea15e9b0c56b7f55f5e40665d5e00baef4f028.zip |
Merge pull request #133 from dotty-staging/more-tests
More tests
Diffstat (limited to 'tests/pos')
79 files changed, 1027 insertions, 0 deletions
diff --git a/tests/pos/bigint.scala b/tests/pos/bigint.scala new file mode 100644 index 000000000..e1aaaf96e --- /dev/null +++ b/tests/pos/bigint.scala @@ -0,0 +1,7 @@ +import scala.math.BigInt +//import BigInt._ +object test { + + 1 * BigInt(0) + +} diff --git a/tests/pos/t1164.scala b/tests/pos/t1164.scala new file mode 100644 index 000000000..ab58c1d6b --- /dev/null +++ b/tests/pos/t1164.scala @@ -0,0 +1,29 @@ + + +object test { + + class Foo[a](val arg : a) + + object Foo { + def apply [a](arg : a, right :a) = new Foo[a](arg) + def unapply [a](m : Foo[a]) = Some (m.arg) + } + + def matchAndGetArgFromFoo[a]( e:Foo[a]):a = {e match { case Foo(x) => x }} + + + // Try the same thing as above but use function as argument to Bar + // constructor + + type FunIntToA [a] = (Int) => a + class Bar[a] (var f: FunIntToA[a]) + + object Bar { + def apply[a](f: FunIntToA[a]) = new Bar[a](f) + def unapply[a](m: Bar[a]) = Some (m.f) + } + + def matchAndGetFunFromBar[a](b:Bar[a]) : FunIntToA[a] = { b match { case Bar(x) => x}} + + +} diff --git a/tests/pos/t1318.scala b/tests/pos/t1318.scala new file mode 100644 index 000000000..34e2bc8dd --- /dev/null +++ b/tests/pos/t1318.scala @@ -0,0 +1,31 @@ +abstract class F { + type mType <: M +} + +abstract class M { self => + + type mType <: M + + type fType = F {type mType >: self.mType } + def fs: List[fType] +} + +abstract class A0 extends M { + type mType = A0 + def fs: List[fType] = Nil +} + +object A extends A0 {} + +abstract class B0 extends M { + type mType = B0 + def fs: List[fType] = Nil +} + +object B extends B0 {} + +object C { + def ab = List(A) ::: List(B) + // the following compiles successfully: + // def ab = List(A) ::: List[M](B) +} diff --git a/tests/pos/t1385.scala b/tests/pos/t1385.scala new file mode 100644 index 000000000..aefd9c35b --- /dev/null +++ b/tests/pos/t1385.scala @@ -0,0 +1,3 @@ +object Test extends Serializable { + private def readResolve: AnyRef = this +} diff --git a/tests/pos/t1391.scala b/tests/pos/t1391.scala new file mode 100644 index 000000000..5178ba987 --- /dev/null +++ b/tests/pos/t1391.scala @@ -0,0 +1,43 @@ +package sandbox + + class hierarOverload { + + /* + * Template structure - using abstract types. + */ + trait AB { + type TA <: A + type TB <: B + + protected trait A { + val entities : List[TB] + } + + protected trait B { + var group : TA + } + } + + /* + * Template instantiation in an object to ease use and globally define + abstract types + */ + object NAnB extends AB { + type TB = nB + type TA = nA + + class nA extends A { + val entities = List[nB]() + } + + class nB extends B { + var group = new nA + } + } + + def foo (): Unit = { + val t = new NAnB.nA + println(t) + } + + } diff --git a/tests/pos/t1422_pos.scala b/tests/pos/t1422_pos.scala new file mode 100644 index 000000000..658f5c730 --- /dev/null +++ b/tests/pos/t1422_pos.scala @@ -0,0 +1,2 @@ +case class A(private val foo:String) +case class B(protected[this] val foo:String) diff --git a/tests/pos/t1438.scala b/tests/pos/t1438.scala new file mode 100644 index 000000000..221c3439d --- /dev/null +++ b/tests/pos/t1438.scala @@ -0,0 +1,10 @@ +class C[A] { + type CC[B] <: C[B] + def aio[T]: T = aio[T] +} +class D[A] extends C[A] { + protected def nv[B](elems: Iterator[B]): CC[B] = { + val x = new D[B] + x.aio[CC[B]] + } +} diff --git a/tests/pos/t1439.scala b/tests/pos/t1439.scala new file mode 100644 index 000000000..0efcc74b6 --- /dev/null +++ b/tests/pos/t1439.scala @@ -0,0 +1,8 @@ +// no unchecked warnings +class View[C[A]] { } + +object Test { + (null: Any) match { + case v: View[_] => + } +} diff --git a/tests/pos/t1480.scala b/tests/pos/t1480.scala new file mode 100644 index 000000000..1d9f94d2e --- /dev/null +++ b/tests/pos/t1480.scala @@ -0,0 +1,6 @@ +class Foo{ + def compare(newP : Any, oldP : Any) : Boolean = (newP,oldP) match { + case (newP : AnyRef, oldP : AnyRef) if newP == oldP => newP == oldP + case (newS : Symbol, oldS: Symbol) if newS == oldS => newS == oldS + } +} diff --git a/tests/pos/t151.scala b/tests/pos/t151.scala new file mode 100644 index 000000000..86667b49f --- /dev/null +++ b/tests/pos/t151.scala @@ -0,0 +1,6 @@ +abstract class Foo { + type T; + def foo(a: T): Int = 0; + val foo: Foo = null; + def a: foo.T = a; +} diff --git a/tests/pos/t1560.scala b/tests/pos/t1560.scala new file mode 100644 index 000000000..dd76392e6 --- /dev/null +++ b/tests/pos/t1560.scala @@ -0,0 +1,13 @@ +object Test extends App { + + trait C[T] { + def t: T + } + + def b: Option[C[_]] = null + + def c = b match { + case Some(b) => b.t + } + +} diff --git a/tests/pos/t1565.scala b/tests/pos/t1565.scala new file mode 100644 index 000000000..59d27a086 --- /dev/null +++ b/tests/pos/t1565.scala @@ -0,0 +1,19 @@ +object Bug1565 { + +// object X0 { 0; (a : Int, b : Int, c : Int) => println(List(a, b)) } // can't parse in Dotty +// def x() = { 0; (a : Int, b : Int) => println(List(a, b)) ; 0 } // can't parse in Dotty + +// (a : Int, b : Int) => println(List(a, b)) not legal as a template statement + + // various function syntaxes to exercise the parser + val xs = List(1,2,3) + xs.filter(x => x < 2) + xs.filter((x) => x < 2) + xs.filter { x => x < 2 } + xs.filter { _ < 2 } + xs.filter (_ < 2) + xs.foreach { e => + val buf0 = e + 1 + buf0 + } +} diff --git a/tests/pos/t1569.scala b/tests/pos/t1569.scala new file mode 100644 index 000000000..a7200a6d1 --- /dev/null +++ b/tests/pos/t1569.scala @@ -0,0 +1,5 @@ +object Bug { + class C { type T } + def foo(x: Int)(y: C)(z: y.T): Unit = {} + foo(3)(new C { type T = String })("hello") +} diff --git a/tests/pos/t159.scala b/tests/pos/t159.scala new file mode 100644 index 000000000..4d67f8aff --- /dev/null +++ b/tests/pos/t159.scala @@ -0,0 +1,22 @@ +object foo { + // the problem seems to appear only + // if "val _" is in the body of a case + def cooked(ckd: StringBuilder): Unit = { + 'a' match { + case '-' => + val _ = ckd.append( '_' ); + case 'v' => + val _ = ckd.append( '_' ); + } + } +} + +object foo1 { + def f(): Unit = { + 1 match { + case 2 => val _ = 1; + case 3 => val _ = 2; + case 4 => val _ = 2; + } + } +} diff --git a/tests/pos/t1591_pos.scala b/tests/pos/t1591_pos.scala new file mode 100644 index 000000000..4f55d7ce1 --- /dev/null +++ b/tests/pos/t1591_pos.scala @@ -0,0 +1,7 @@ +trait A + +object Test { + lazy val a = new A { + object Zenek + } +} diff --git a/tests/pos/t160.scala b/tests/pos/t160.scala new file mode 100644 index 000000000..91ac2ba84 --- /dev/null +++ b/tests/pos/t160.scala @@ -0,0 +1,3 @@ +class Foo(s:String) { + def this() = { this("DEFAULT") } +} diff --git a/tests/pos/t1642b.scala b/tests/pos/t1642b.scala new file mode 100644 index 000000000..72e53b0c9 --- /dev/null +++ b/tests/pos/t1642b.scala @@ -0,0 +1,6 @@ +package x +abstract class H[A] { + type P <: R[P] + def a: P +} +class R[F] diff --git a/tests/pos/t1659.scala b/tests/pos/t1659.scala new file mode 100644 index 000000000..10470d66f --- /dev/null +++ b/tests/pos/t1659.scala @@ -0,0 +1,4 @@ +trait Y { type X } +trait W { def u[A](v : Y { type X = A }) : Unit } +class Z extends W { def u[A](v : Y { type X = A }) = null } + diff --git a/tests/pos/t1675.scala b/tests/pos/t1675.scala new file mode 100644 index 000000000..8630890ee --- /dev/null +++ b/tests/pos/t1675.scala @@ -0,0 +1,11 @@ +package a +object Foo extends pack.Bar { + for(i <- 0 to 10) { + test("") + } +} +package pack { + class Bar { + protected def test(s: String*): Unit = {} + } +} diff --git a/tests/pos/t1693.scala b/tests/pos/t1693.scala new file mode 100644 index 000000000..881bf89a0 --- /dev/null +++ b/tests/pos/t1693.scala @@ -0,0 +1,9 @@ +object Test { + class Foo + class SomeOps(x : Foo) { def foo(x: String) = 1 } + class OtherOps(x : Foo) { def foo(x: Int) = 1 } + implicit def mkSomeOps(x: Foo) : SomeOps = new SomeOps(x) + implicit def mkOtherOps(x: Foo) : OtherOps = new OtherOps(x) + + (new Foo).foo(1) +} diff --git a/tests/pos/t1722-A.scala b/tests/pos/t1722-A.scala new file mode 100644 index 000000000..d059bf22f --- /dev/null +++ b/tests/pos/t1722-A.scala @@ -0,0 +1,10 @@ +sealed trait Top +trait C { + private object P extends Top +} +/* +$ scala -e 'new AnyRef with C' +error: error while loading Top, class file '/private/tmp/bobobo/./Top.class' is broken +(error reading Scala signature of /private/tmp/bobobo/./Top.class: malformed Scala signature of Top at 185; reference value P of trait C refers to nonexisting symbol.) +one error found +*/ diff --git a/tests/pos/t1722/Test.scala b/tests/pos/t1722/Test.scala new file mode 100755 index 000000000..f236d3fdc --- /dev/null +++ b/tests/pos/t1722/Test.scala @@ -0,0 +1,5 @@ +package t1722 + +object Test { + val x = new AnyRef with C +} diff --git a/tests/pos/t1722/Top.scala b/tests/pos/t1722/Top.scala new file mode 100755 index 000000000..4ac52412a --- /dev/null +++ b/tests/pos/t1722/Top.scala @@ -0,0 +1,13 @@ +package t1722 + +sealed trait Top +trait C { + private object P extends Top +} +/* +$ scala -e 'new AnyRef with C' +error: error while loading Top, class file '/private/tmp/bobobo/./Top.class' is broken +(error reading Scala signature of /private/tmp/bobobo/./Top.class: malformed Scala signature of Top at 185; reference value P of trait C refers to nonexisting symbol.) +one error found +Martin: I think this has to do with children property. +*/ diff --git a/tests/pos/t175.scala b/tests/pos/t175.scala new file mode 100644 index 000000000..4c0eb28ba --- /dev/null +++ b/tests/pos/t175.scala @@ -0,0 +1,3 @@ +abstract class C { + def this(x: Unit) = { this() } +} diff --git a/tests/pos/t177.scala b/tests/pos/t177.scala new file mode 100644 index 000000000..33b4de926 --- /dev/null +++ b/tests/pos/t177.scala @@ -0,0 +1,8 @@ +class A { + def foo = { + object Y { + def bar = 1; + } + Y.bar + } +} diff --git a/tests/pos/t1785.scala b/tests/pos/t1785.scala new file mode 100644 index 000000000..0b1fafb27 --- /dev/null +++ b/tests/pos/t1785.scala @@ -0,0 +1,7 @@ +class t1785 { + def apply[T](x: Int) = 1 +} + +object test { + (new t1785)[Int](1) +} diff --git a/tests/pos/t1786-counter.scala b/tests/pos/t1786-counter.scala new file mode 100644 index 000000000..a2431343d --- /dev/null +++ b/tests/pos/t1786-counter.scala @@ -0,0 +1,38 @@ +trait ShapeLevel + +object Fail { + abstract class ProductNodeShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] extends Shape[Level, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] + } + + abstract class Shape[Level <: ShapeLevel, -Mixed_, Unpacked_, Packed_] + + final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] = ??? + } + + trait ShapeLevel +} + +object Ok { + abstract class Shape[Level <: ShapeLevel, -Mixed_, Unpacked_, Packed_] + + abstract class ProductNodeShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] extends Shape[Level, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] + } + + final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] = ??? + } +} + +// This is why we reverted the fix for SI-1786 -- see SI-6169 for a potential alternative that could be extended to cover this. +// both objects type check on 2.10.3, but only Ok was accepted by 2.11 after the original fix to SI-1786. +// Fail results in: +/* +t1786-counter.scala:10: error: class TupleShape needs to be abstract, since method copy in class ProductNodeShape of type (shapes: Seq[Fail.Shape[_, _, _, _]])Fail.Shape[Level, _, _, _] is not defined +(Note that Seq[Fail.Shape[_, _, _, _]] does not match Seq[Fail.Shape[_ <: Fail.ShapeLevel, _, _, _]]: their type parameters differ) + final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { + ^ +one error found +*/ diff --git a/tests/pos/t1786-cycle.scala b/tests/pos/t1786-cycle.scala new file mode 100644 index 000000000..9de149fbc --- /dev/null +++ b/tests/pos/t1786-cycle.scala @@ -0,0 +1,57 @@ +trait GenTraversableLike[+A, +Repr] extends Any + +object O { + (null: Any) match { + case _: LongTraversableLike[_] => + } +} + +trait LongTraversable extends LongTraversableLike[LongTraversable] + +trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenTraversableLike[Any, Repr] + +/* +% scalac-hash v2.11.0-M8 test/files/pos/t1786-cycle.scala +[warn] v2.11.0-M8 failed, using closest available +test/files/pos/t1786-cycle.scala:11: error: illegal cyclic reference involving trait LongTraversableLike +trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenTraversableLike[Any, Repr] + ^ +one error found + +Okay again after SI-1786 was reverted. + + +|-- object O BYVALmode-EXPRmode (site: package <empty>) +| |-- super EXPRmode-POLYmode-QUALmode (silent: <init> in O) +| | |-- this EXPRmode (silent: <init> in O) +| | | \-> O.type +| | \-> O.type +| |-- (null: Any) match { case (_: LongTraversableLike[(_ @ <em... BYVALmode-EXPRmode (site: value <local O> in O) +| | |-- (null: Any) BYVALmode-EXPRmode (site: value <local O> in O) +| | | |-- Any TYPEmode (site: value <local O> in O) +| | | | \-> Any +| | | |-- null : pt=Any EXPRmode (site: value <local O> in O) +| | | | \-> Null(null) +| | | \-> Any +| | |-- (_: LongTraversableLike[(_ @ <empty>)]) : pt=Any PATTERNmode (site: value <local O> in O) enrichment only +| | | |-- LongTraversableLike[(_ @ <empty>)] TYPEPATmode-TYPEmode (site: value <local O> in O) enrichment only +| | | | |-- <: LongTraversableLike[Repr] TYPEmode (site: type Repr in <empty>) +| | | | | |-- LongTraversableLike[Repr] TYPEmode (site: type Repr in <empty>) +| | | | | | |-- Repr NOmode (site: type Repr in <empty>) +| | | | | | | \-> Repr +| | | | | | \-> LongTraversableLike[Repr] +| | | | | [adapt] <: LongTraversableLike[Repr] is now a TypeTree( <: LongTraversableLike[Repr]) +| | | | | \-> <: LongTraversableLike[Repr] +| | | | |-- (_ @ <empty>) TYPEPATmode-TYPEmode (site: value <local O> in O) enrichment only +| | | | | \-> _ +| | | | |-- GenTraversableLike FUNmode-TYPEmode (site: trait LongTraversableLike) +| | | | | \-> GenTraversableLike +| | | | |-- GenTraversableLike[Any, Repr] TYPEmode (site: trait LongTraversableLike) +| | | | | |-- Any TYPEmode (site: trait LongTraversableLike) +| | | | | | \-> Any +| | | | | |-- Repr TYPEmode (site: trait LongTraversableLike) +| | | | | | \-> Repr +| | | | | caught scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving trait LongTraversableLike: while typing GenTraversableLike[Any, Repr] +test/files/pos/t1786-cycle.scala:11: error: illegal cyclic reference involving trait LongTraversableLike +trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenT +*/ diff --git a/tests/pos/t1789.scala b/tests/pos/t1789.scala new file mode 100644 index 000000000..1a37d48d0 --- /dev/null +++ b/tests/pos/t1789.scala @@ -0,0 +1,5 @@ +object S { + try { } + catch { case _ => } + finally { while(true) { } } +} diff --git a/tests/pos/t1798.scala b/tests/pos/t1798.scala new file mode 100644 index 000000000..1624e3025 --- /dev/null +++ b/tests/pos/t1798.scala @@ -0,0 +1,10 @@ +object Foo { private def bar(): Int = 55 } +class Foo(x: Int) { def this() = this(Foo.bar()) } + +/* + * scalac28 a.scala +a.scala:2: error: method bar cannot be accessed in object Foo +class Foo(x: Int) { def this() = this(Foo.bar()) } + ^ +one error found +*/ diff --git a/tests/pos/t183.scala b/tests/pos/t183.scala new file mode 100644 index 000000000..d7ed27f73 --- /dev/null +++ b/tests/pos/t183.scala @@ -0,0 +1,4 @@ +object Test { + new Foo(0); + class Foo(x: Int); +} diff --git a/tests/pos/t1832.scala b/tests/pos/t1832.scala new file mode 100644 index 000000000..9ad9703c2 --- /dev/null +++ b/tests/pos/t1832.scala @@ -0,0 +1,10 @@ +trait Cloning { + trait Foo + def fn(g: Any => Unit): Foo + + class Star { def *(a: Cloning.this.Foo): Cloning.this.Foo } + + implicit def mkStar(i: Int): Star = new Star { def *(a: Foo): Foo = null } + + val pool = 4 * fn { case ghostSYMBOL: Int => ghostSYMBOL * 2 } +} diff --git a/tests/pos/t1843.scala b/tests/pos/t1843.scala new file mode 100644 index 000000000..e9b5c5d2d --- /dev/null +++ b/tests/pos/t1843.scala @@ -0,0 +1,25 @@ +/** +* Scala Compiler Will Crash On this File +* ... Or Will It? +* +*/ + +object Crash { + 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 + def crash(updates: List[StateUpdate[_]]): Unit = { + updates match { + case Nil => + case u::us => + u match { + //Line below seems to be the crashing line + case StateUpdate(key, newValue) if (key == IntegerUpdateType) => + println("Requires a statement to induce the crash") + case _ => + } + } + } +} diff --git a/tests/pos/t1858.scala b/tests/pos/t1858.scala new file mode 100644 index 000000000..c06e73e7e --- /dev/null +++ b/tests/pos/t1858.scala @@ -0,0 +1,13 @@ +import scala.collection.immutable.Stack + +object Test { + + def test = { + val s = new Stack[Int] + s.push(1) + s.push(1, 2) + s.push(1, 2, 3) + s.push(1, 2, 3, 4) + } + +} diff --git a/tests/pos/t1896/D0.scala b/tests/pos/t1896/D0.scala new file mode 100644 index 000000000..6b3150d96 --- /dev/null +++ b/tests/pos/t1896/D0.scala @@ -0,0 +1,11 @@ +package p + +class X[T] + +trait A { + def m(s:X[_]): Unit = {} +} + +trait B extends A { + def f: Unit = { super.m(null) } +} diff --git a/tests/pos/t1896/D1.scala b/tests/pos/t1896/D1.scala new file mode 100644 index 000000000..e1ab50679 --- /dev/null +++ b/tests/pos/t1896/D1.scala @@ -0,0 +1,2 @@ +package p +class C extends B diff --git a/tests/pos/t1942/A_1.scala b/tests/pos/t1942/A_1.scala new file mode 100644 index 000000000..4915b54a6 --- /dev/null +++ b/tests/pos/t1942/A_1.scala @@ -0,0 +1,11 @@ +class A { + def foo(x: Int) = 0 + def foo(x: String) = 1 +} + +class ann(x: Int) extends annotation.StaticAnnotation + +class t { + val a = new A + @ann(a.foo(1)) def bar = 1 +} diff --git a/tests/pos/t1942/Test_2.scala b/tests/pos/t1942/Test_2.scala new file mode 100644 index 000000000..6c045bbce --- /dev/null +++ b/tests/pos/t1942/Test_2.scala @@ -0,0 +1,3 @@ +class Test { + println(new t) +} diff --git a/tests/pos/t1957.scala b/tests/pos/t1957.scala new file mode 100644 index 000000000..711ce17de --- /dev/null +++ b/tests/pos/t1957.scala @@ -0,0 +1,38 @@ +object Test { + abstract class Settings {} + + abstract class Grist + { self => + type settingsType <: Settings + type moduleType <: Module {type settingsType = self.settingsType} + val module: moduleType + } + + abstract class Tool + { self => + type settingsType <: Settings + type moduleType = Module { type settingsType = self.settingsType } + type gristType = Grist { type moduleType <: self.moduleType; type settingsType <: self.settingsType } + + def inputGrist: List[gristType] + } + + abstract class Module + { self => + type settingsType <: Settings + final type commonModuleType = Module {type settingsType = self.settingsType} + type selfType >: self.type <: commonModuleType + + // BTW: if we use the commented out type decls, the code compiles successfully + // type gristType = Grist {type settingsType <: self.settingsType; type moduleType <: commonModuleType } + + val tools: List[Tool {type settingsType = self.settingsType}] + + protected def f: List[commonModuleType] = + { + val inputGrists = tools.flatMap(_.inputGrist) // val inputGrists: List[gristType] = + inputGrists.map(_.module) + } + + } +} diff --git a/tests/pos/t1974.scala b/tests/pos/t1974.scala new file mode 100644 index 000000000..3f4d41e7f --- /dev/null +++ b/tests/pos/t1974.scala @@ -0,0 +1,20 @@ +object Broken { + private var map = Map[Class[_], String]() + + def addToMap(c : Class[_], s : String) = map += (c -> s) + def fetch(c : Class[_]) = map(c) +} + +object Works { + private var map = Map[Class[_], String]() + + def addToMap(c : Class[_], s : String) = map += ((c, s)) + def fetch(c : Class[_]) = map(c) +} + +object Works2 { + private var map = Map[Class[_], String]() + + def addToMap(c : Class[_], s : String) = map += ((c : Class[_]) -> s) + def fetch(c : Class[_]) = map(c) +} diff --git a/tests/pos/t1987a.scala b/tests/pos/t1987a.scala new file mode 100644 index 000000000..ccab13371 --- /dev/null +++ b/tests/pos/t1987a.scala @@ -0,0 +1,8 @@ +package object overloading { + def bar(f: (Int) => Unit): Unit = () + def bar(f: (Int, Int) => Unit): Unit = () +} + +class PackageObjectOverloadingTest { + overloading.bar( (i: Int) => () ) // doesn't compile. +} diff --git a/tests/pos/t1987b/a.scala b/tests/pos/t1987b/a.scala new file mode 100644 index 000000000..ff27044b6 --- /dev/null +++ b/tests/pos/t1987b/a.scala @@ -0,0 +1,7 @@ +package bug + +// goes with t1987b.scala +package object packageb { + def func(a: Int) = () + def func(a: String) = () +} diff --git a/tests/pos/t1987b/b.scala b/tests/pos/t1987b/b.scala new file mode 100644 index 000000000..a469ca6ea --- /dev/null +++ b/tests/pos/t1987b/b.scala @@ -0,0 +1,10 @@ +// compile with t1987a.scala + +package bug.packageb +// Note that the overloading works if instead of being in the package we import it: +// replace the above line with import bug.packageb._ + +class Client { + val x = func(1) // doesn't compile: type mismatch; found: Int(1) required: String + val y = func("1") // compiles +} diff --git a/tests/pos/t1996.scala b/tests/pos/t1996.scala new file mode 100644 index 000000000..273012819 --- /dev/null +++ b/tests/pos/t1996.scala @@ -0,0 +1,19 @@ +object forbug { + val l1 = List(List(ValDef(new A)), List(ValDef(new A))) + for ((e1s, e2s) <- l1.zip(l1); + (e1, e2) <- e1s.zip(e2s)) { + e1.a.doSome(20) +// () + } +} + + +class A { + def doSome(a: Int): this.type = { + println(a) + this + } +} + +case class ValDef(a: A) + diff --git a/tests/pos/t201.scala b/tests/pos/t201.scala new file mode 100644 index 000000000..b0c6b8da4 --- /dev/null +++ b/tests/pos/t201.scala @@ -0,0 +1,7 @@ +class C[a] { def f: a = f; } +class D[b] { class E extends C[b]; } +object Test { + val d = new D[Int]; + def e = new d.E; + e.f; +} diff --git a/tests/pos/t2018.scala b/tests/pos/t2018.scala new file mode 100644 index 000000000..198b4be42 --- /dev/null +++ b/tests/pos/t2018.scala @@ -0,0 +1,15 @@ +class A { + val b = new B + + def getChildren = List(new A).iterator + + class B { + private def check = true + + private def getAncestor(p: A): A = { + val c = (p.getChildren.find(_.b.check)) match {case Some(d) => d case None => p} + + if (c == p) p else c.b.getAncestor(c) + } + } +} diff --git a/tests/pos/t2023.scala b/tests/pos/t2023.scala new file mode 100644 index 000000000..21c6fc96a --- /dev/null +++ b/tests/pos/t2023.scala @@ -0,0 +1,16 @@ +trait C[A] + +object C { + implicit def ipl[A](implicit from: A => Ordered[A]): C[A] = null +} + +object P { + def foo[A](i: A, j: A)(implicit c: C[A]): Unit = () +} + +class ImplicitChainTest { + def testTrivial: Unit = { + P.foo('0', '9') + P.foo('0', '9') + } +} diff --git a/tests/pos/t2038.scala b/tests/pos/t2038.scala new file mode 100644 index 000000000..8c8ca44da --- /dev/null +++ b/tests/pos/t2038.scala @@ -0,0 +1,5 @@ +class Test { + List(Some(classOf[java.lang.Integer]), Some(classOf[Int])).map { + case Some(f: Class[_]) => f.cast(???) + } +} diff --git a/tests/pos/t2060.scala b/tests/pos/t2060.scala new file mode 100755 index 000000000..0b9079062 --- /dev/null +++ b/tests/pos/t2060.scala @@ -0,0 +1,44 @@ +/* The problem here is that we cannot insert an implicit to + * add a polymorphic method which is then instantiated to the + * right type. When searching for the implicit in the `fails to compile + * line': + * + * val failure = 1.0 + new Op[Int] + * + * we reduce the problem to finding a function from Double to + * {+: _ >: Op[Int] <: Any}, that is, a method which takes + * an argument which is an Op[Int] or a supertype thereof. + * Class Rich is not a subtype of this structural record, because + * polymorphic method instantiation is not contained in subtyping. + * That is: The method type [I](op : Op[I]): Op[I] is not a subtype + * of (Op[Int]): Op[Int]. + * At present it is unclear whether this problem can be solved. + */ +object Test { + class Op[I]; + class IntOp extends Op[Int]; + + class Rich(x : Double) { + def + (op : IntOp): IntOp = op; + def + [I](op : Op[I]): Op[I] = op; + def plus [I](op : Op[I]): Op[I] = op; + } + + implicit def iToRich(x : Double): Test.Rich = + new Rich(x); + + // fails to compile + val x = 1.0 + new Op[Int] + + // works as expected -- + // problem isn't in adding new "+" + val a = 1.0 + new IntOp; + + // works as expected -- + // problem isn't in binding type variable I + val b = 1.0 plus new Op[Int]; + + // works as expected -- + // problem isn't in using Rich.+[I](op : Op[I]) + val c = iToRich(1.0) + new Op[Int]; +} diff --git a/tests/pos/t2081.scala b/tests/pos/t2081.scala new file mode 100644 index 000000000..395134f71 --- /dev/null +++ b/tests/pos/t2081.scala @@ -0,0 +1,11 @@ +object ScalaForRubyists { + class RichInt(n: Int) { + def days = 1000*60*60*24*n + } + + implicit def RichInt(n: Int): RichInt = new RichInt(n) + + val x = 10.days + // a couple parser corner cases I wanted not to break + val y = 5.0e0 + 5e7 +} diff --git a/tests/pos/t2082.scala b/tests/pos/t2082.scala new file mode 100755 index 000000000..a7ee3789b --- /dev/null +++ b/tests/pos/t2082.scala @@ -0,0 +1,39 @@ + +trait Mapper[T <: Mapper[T]] + +trait KeyedMapper[KeyType, T <: KeyedMapper[KeyType, T]] extends Mapper[T] + + +trait KeyedMetaMapper[KeyType, T <: KeyedMapper[KeyType, T]] + +trait MappedForeignKey[KeyType, Owner <: Mapper[Owner], Other <: KeyedMapper[KeyType, Other]] + +trait IdPK + +class TestSubject extends KeyedMapper[Long, TestSubject] with IdPK + +class TestRun extends KeyedMapper[Long, TestRun] with IdPK { + object testSubject extends MappedForeignKey[Long, TestRun, TestSubject] +} + +object TestRun extends TestRun with KeyedMetaMapper[Long, TestRun] + +class MetaTestSubject extends TestSubject with KeyedMetaMapper[Long, TestSubject] +object TestSubject extends MetaTestSubject + +object Main { + + def oneToOneJoin[PType <: KeyedMapper[Long, PType] with IdPK, + CType <: KeyedMapper[Long, CType] with IdPK, + CMetaType <: CType with KeyedMetaMapper[Long, CType], + FKType <: MappedForeignKey[Long, PType, CType]] + (parents: List[PType], metaMapper: CMetaType, keyGetter: (PType) => FKType ): + Map[Long, CType] = Map.empty + + def callIt: Unit = { + oneToOneJoin[TestRun, TestSubject, MetaTestSubject, + MappedForeignKey[Long, TestRun, TestSubject]]( + List(), TestSubject, (tr: TestRun) => tr.testSubject) + } + +} diff --git a/tests/pos/t2094.scala b/tests/pos/t2094.scala new file mode 100644 index 000000000..6b6c4f077 --- /dev/null +++ b/tests/pos/t2094.scala @@ -0,0 +1,31 @@ +object Test extends App { + // compiles: + Map[Int, Value]( + 0 -> KnownType(classOf[Object]), + 1 -> UnknownValue()) + + // does not compile: + Map( + 0 -> KnownType(classOf[Object]), + 1 -> UnknownValue()) + + // Experiment.scala:10: error: type mismatch; + // found : (Int, KnownType) + // required: (Int, Product with Value{def getType: Option[java.lang.Class[_$$2]]}) where type _$$2 + // 0 -> KnownType(classOf[Object]), + // ^ + // one error found +} +sealed trait Value { + def getType: Option[Class[_]] +} + +case class UnknownValue() extends Value { + def getType = None + // compiles if changed to: + // def getType: Option[Class[_]] = None +} + +case class KnownType(typ: Class[_]) extends Value { + def getType = Some(typ) +} diff --git a/tests/pos/t210.scala b/tests/pos/t210.scala new file mode 100644 index 000000000..f0b907aa5 --- /dev/null +++ b/tests/pos/t210.scala @@ -0,0 +1,17 @@ +trait Lang1 { + trait Exp; + trait Visitor { def f(left: Exp): Unit } + class Eval1 extends Visitor { self: Visitor => + def f(left: Exp) = () + } +} + +trait Lang2 extends Lang1 { + class Eval2 extends Eval1 { self: Visitor => } +} +/* +object Main with App { + val lang2 = new Lang2 {} + val eval = new lang2.Eval2 +} +*/ diff --git a/tests/pos/t211.scala b/tests/pos/t211.scala new file mode 100644 index 000000000..d51c9706d --- /dev/null +++ b/tests/pos/t211.scala @@ -0,0 +1,8 @@ +trait A; +trait B; +class Foo extends A with B { self: A with B => } +object Test extends App { + new Foo(); + Console.println("t211 completed"); +} + diff --git a/tests/pos/t2119.scala b/tests/pos/t2119.scala new file mode 100644 index 000000000..b9cb4d9c6 --- /dev/null +++ b/tests/pos/t2119.scala @@ -0,0 +1,4 @@ +class A { + val orig = new java.util.ArrayList[String] + val copy = new java.util.ArrayList(orig) +} diff --git a/tests/pos/t2127.scala b/tests/pos/t2127.scala new file mode 100644 index 000000000..88cc9e708 --- /dev/null +++ b/tests/pos/t2127.scala @@ -0,0 +1,5 @@ +class Foo private (val value : Int) + +abstract class Bar(val ctor : (Int) => Foo) + +object Foo extends Bar(new Foo(_)) //<--- ILLEGAL ACCESS diff --git a/tests/pos/t2130-1.scala b/tests/pos/t2130-1.scala new file mode 100644 index 000000000..8dd61c4d3 --- /dev/null +++ b/tests/pos/t2130-1.scala @@ -0,0 +1,5 @@ +package foo + +package object bar { + case class Bippy(x: Int) { } +} diff --git a/tests/pos/t2130-2.scala b/tests/pos/t2130-2.scala new file mode 100644 index 000000000..1d0b33c3e --- /dev/null +++ b/tests/pos/t2130-2.scala @@ -0,0 +1,17 @@ +package foo + +package object bar { + class Bippy(x: Int) { + class Ding + object Ding + case class Dong(x: Float) + } + object Bippy { + class Dingus + object Dingus + case class Dongus(x: Float) + + def apply(xs: Int*) = new Bippy(xs.sum) + def apply() = new Bippy(5) + } +} diff --git a/tests/pos/t2133.scala b/tests/pos/t2133.scala new file mode 100644 index 000000000..02ef43c21 --- /dev/null +++ b/tests/pos/t2133.scala @@ -0,0 +1,18 @@ +trait Foo { + object bar { + private def fn() = 5 + } +} + +trait Foo2 { + object bip { + def fn() = 10 + } +} + +class Bob extends AnyRef with Foo with Foo2 { + import bip._ + import bar._ + + def go() = fn() +} diff --git a/tests/pos/t2168.scala b/tests/pos/t2168.scala new file mode 100644 index 000000000..21afb239a --- /dev/null +++ b/tests/pos/t2168.scala @@ -0,0 +1,4 @@ +object Test extends App { + def foo1(x: AnyRef) = x match { case x: Function0[_] => x() } + def foo2(x: AnyRef) = x match { case x: Function0[Any] => x() } +} diff --git a/tests/pos/t2171.flags b/tests/pos/t2171.flags new file mode 100644 index 000000000..eb4d19bcb --- /dev/null +++ b/tests/pos/t2171.flags @@ -0,0 +1 @@ +-optimise
\ No newline at end of file diff --git a/tests/pos/t2171.scala b/tests/pos/t2171.scala new file mode 100644 index 000000000..6c754c76a --- /dev/null +++ b/tests/pos/t2171.scala @@ -0,0 +1,7 @@ +final object test { + def logIgnoredException(msg: => String) = + try 0 catch { case ex => println(msg) } + + def main (args: Array[String]): Unit = + while (true) logIgnoredException ("...") +} diff --git a/tests/pos/t2179.scala b/tests/pos/t2179.scala new file mode 100755 index 000000000..89e22b6e2 --- /dev/null +++ b/tests/pos/t2179.scala @@ -0,0 +1,3 @@ +object Test { + (Nil:List[List[Double]]).reduceLeft((_: Any, _: Any) => Nil.indices.map(_ => 0d)) +} diff --git a/tests/pos/t2183.scala b/tests/pos/t2183.scala new file mode 100644 index 000000000..1243568b6 --- /dev/null +++ b/tests/pos/t2183.scala @@ -0,0 +1,5 @@ +import scala.collection.mutable._ + +object Test { + val m = new HashSet[String] with SynchronizedSet[String] +} diff --git a/tests/pos/t2187-2.scala b/tests/pos/t2187-2.scala new file mode 100644 index 000000000..506cc496f --- /dev/null +++ b/tests/pos/t2187-2.scala @@ -0,0 +1,7 @@ +class Test { + def test[A](list: List[A]) = list match { + case Seq(x, y) => "xy" + case Seq(x) => "x" + case _ => "something else" + } +} diff --git a/tests/pos/t2187.scala b/tests/pos/t2187.scala new file mode 100644 index 000000000..8a3353154 --- /dev/null +++ b/tests/pos/t2187.scala @@ -0,0 +1,7 @@ +// bug #2187 +object Test extends App { + def foo(xs:List[String]) = xs match { + case Seq(x) => x + case Seq(x,y) => "" + } +} diff --git a/tests/pos/t2194.scala b/tests/pos/t2194.scala new file mode 100644 index 000000000..e87be509d --- /dev/null +++ b/tests/pos/t2194.scala @@ -0,0 +1,8 @@ +// tricky to do differently? +class C + +object Test { + def f = { object o extends C; o} + val y: C = f + val x = f +} diff --git a/tests/pos/t2208_pos.scala b/tests/pos/t2208_pos.scala new file mode 100644 index 000000000..dd6d686ba --- /dev/null +++ b/tests/pos/t2208_pos.scala @@ -0,0 +1,8 @@ +object Test { + class A + + class B[X] + type Alias[X <: A] = B[X] + + val foo: B[A] = new Alias[A] // check that type aliases can be instantiated +} diff --git a/tests/pos/t2234.scala b/tests/pos/t2234.scala new file mode 100644 index 000000000..218e9f5e5 --- /dev/null +++ b/tests/pos/t2234.scala @@ -0,0 +1,4 @@ +object Test extends App { + val res0 = 1 #:: Stream.empty + res0 match { case 1 #:: xs => xs } +} diff --git a/tests/pos/t2260.scala b/tests/pos/t2260.scala new file mode 100644 index 000000000..4e4cc5ab2 --- /dev/null +++ b/tests/pos/t2260.scala @@ -0,0 +1,10 @@ +package top + +class Text(val value: String) extends Ordered[Text] { + def compare(that: Text) = value.compare(that.value) +} + +object Index { + import scala.collection.immutable.TreeMap + val tree = TreeMap.empty[Text, String] +} diff --git a/tests/pos/t2261.scala b/tests/pos/t2261.scala new file mode 100644 index 000000000..06360d500 --- /dev/null +++ b/tests/pos/t2261.scala @@ -0,0 +1,9 @@ +class Bob[T] +object Test { + implicit def foo2bar[T](xs: List[T]): Bob[T] = new Bob[T] + var x: Bob[Int] = null + x = List(1,2,3) + // the problem here was that somehow the type variable that was used to infer the type argument for List.apply + // would accumulate several conflicting constraints + // can't reproduce with +} diff --git a/tests/pos/t229.scala b/tests/pos/t229.scala new file mode 100644 index 000000000..72ddfa74f --- /dev/null +++ b/tests/pos/t229.scala @@ -0,0 +1,3 @@ +class Test extends java.util.ArrayList[Object] { + override def add(index: Int, element: java.lang.Object): Unit = {} +} diff --git a/tests/pos/t2293.scala b/tests/pos/t2293.scala new file mode 100644 index 000000000..536d4ec3d --- /dev/null +++ b/tests/pos/t2293.scala @@ -0,0 +1,5 @@ +import scala.collection.JavaConversions._ + +object Test { + val m: java.util.Map[String,String] = collection.mutable.Map("1"->"2") +} diff --git a/tests/pos/t2305.scala b/tests/pos/t2305.scala new file mode 100644 index 000000000..3338ab911 --- /dev/null +++ b/tests/pos/t2305.scala @@ -0,0 +1,26 @@ +import java.util.ArrayList + +trait Bind[Z[_]] + +class MySerializable[X] extends java.io.Serializable + +object Bind { + implicit val JavaArrayListBind: Bind[ArrayList] = new Bind[ArrayList] {} + implicit val MySerializableBind: Bind[MySerializable] = new Bind[MySerializable] {} +} + +object works { + // this works fine: + def runbind(implicit bind: Bind[MySerializable]): Unit = {} + runbind +} + +object breaks { + def runbind(implicit bind: Bind[ArrayList]): Unit = {} + runbind + /*java.lang.AssertionError: assertion failed: java.io.Serializable + at scala.Predef$.assert(Predef.scala:107) + at scala.tools.nsc.symtab.Types$TypeRef.transform(Types.scala:1417) + at scala.tools.nsc.symtab.Types$TypeRef.baseType(Types.scala:1559) + */ +} diff --git a/tests/pos/t2310.scala b/tests/pos/t2310.scala new file mode 100644 index 000000000..68912b496 --- /dev/null +++ b/tests/pos/t2310.scala @@ -0,0 +1,38 @@ +import scala.Stream._ + +object consistencyError { + /* this gives an error: + Consistency problem compiling (virtual file)! + Trying to call method body%1(List(scala.collection.immutable.Stream[A])) with arguments (List(tp2, temp6, temp5)) + case (l #:: ls, rs) => None + ^ + scala.tools.nsc.symtab.Types$TypeError: too many arguments for method body%1: (val rs: scala.collection.immutable.Stream[A])None.type + + two errors found + vss(0) = + args = List(tp2, temp6, temp5) + vss(1) = value rs, value ls, value l + args = List(tp2, temp6, temp5) + targets(0) = FinalState(,scala.None) + targets(1) = FinalState(,scala.None) + labels(1) = method body%1 + labels(0) = method body%0 + bx = 1 + label.tpe = (val rs: scala.collection.immutable.Stream[A])None.type + */ + def crash[A](lefts: Stream[A], rights: Stream[A]) = (lefts, rights) match { + case (Stream.Empty, Stream.Empty) => None + case (l #:: ls, rs) => None + } + + // These work + // def works1[A](lefts: Stream[A]) = lefts match { + // case Stream.Empty => None + // case l #:: ls => None + // } + // + // def works2[A](lefts: Stream[A], rights: Stream[A]) = (lefts, rights) match { + // case (Stream.Empty, Stream.Empty) => None + // case (ls, rs) => None + // } +} diff --git a/tests/pos/t2331.scala b/tests/pos/t2331.scala new file mode 100644 index 000000000..a7f80ac98 --- /dev/null +++ b/tests/pos/t2331.scala @@ -0,0 +1,11 @@ +trait C { + def m[T]: T +} + +object Test { + val o /*: C --> no crash*/ = new C { + def m[T]: Nothing /*: T --> no crash*/ = sys.error("omitted") + } + + o.m[Nothing] +} diff --git a/tests/pos/t2399.scala b/tests/pos/t2399.scala new file mode 100644 index 000000000..a99998a0a --- /dev/null +++ b/tests/pos/t2399.scala @@ -0,0 +1,14 @@ +trait That1[A] +trait That2[A, R <: That2[A, R]] + +trait T[A, This >: Null <: That1[A] with T[A, This]] extends That2[A, This] { + self: This => + + private var next: This = _ + def isEmpty = next eq null + + def length: Int = { + def loop(x: This, cnt: Int): Int = if (x.isEmpty) cnt else loop(x.next, cnt + 1) + loop(self, 0) + } +} diff --git a/tests/pos/t2429.scala b/tests/pos/t2429.scala new file mode 100755 index 000000000..4cda3bde1 --- /dev/null +++ b/tests/pos/t2429.scala @@ -0,0 +1,25 @@ +object Msg { + trait T + + trait TSeq + + object TSeq { + implicit def fromSeq(s: Seq[T]): TSeq = sys.error("stub") + } + + def render: Unit = { + val msgs: TSeq = (List[(Any, Any)]().flatMap { + case (a, b) => { + a match { + case _ => b match { + case _ => sys.error("stub") + } + } + } + } /*: Seq[T] Adding this type annotation avoids the compile error.*/) + } +} +object Oops { + implicit def someImplicit(s: Seq[_]): String = sys.error("stub") + def item: String = Nil map { case e: Any => e } +} diff --git a/tests/pos/typeinferNull.scala b/tests/pos/typeinferNull.scala new file mode 100644 index 000000000..ba25ae181 --- /dev/null +++ b/tests/pos/typeinferNull.scala @@ -0,0 +1,9 @@ +object typeinferNull { + + val x1 = null :: Nil + val x2 = List(null) + + var y1: List[Null] = x1 + y1 = x2 + +} |