From 82c4db686d07ae8e91f157f5c8b55a1a76917941 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 5 May 2014 18:34:59 +0200 Subject: Pos tests t17xx - t19xx --- tests/pos/t160.scala | 3 +++ tests/pos/t1642b.scala | 6 +++++ tests/pos/t1659.scala | 4 +++ tests/pos/t1675.scala | 11 +++++++++ tests/pos/t1722-A.scala | 10 ++++++++ tests/pos/t1722/Test.scala | 5 ++++ tests/pos/t1722/Top.scala | 13 ++++++++++ tests/pos/t175.scala | 3 +++ tests/pos/t177.scala | 8 ++++++ tests/pos/t1785.scala | 7 ++++++ tests/pos/t1786-counter.scala | 38 +++++++++++++++++++++++++++++ tests/pos/t1786-cycle.scala | 57 +++++++++++++++++++++++++++++++++++++++++++ tests/pos/t1789.scala | 5 ++++ tests/pos/t1798.scala | 10 ++++++++ tests/pos/t183.scala | 4 +++ tests/pos/t1843.scala | 25 +++++++++++++++++++ tests/pos/t1858.scala | 13 ++++++++++ tests/pos/t1896/D0.scala | 11 +++++++++ tests/pos/t1896/D1.scala | 2 ++ tests/pos/t1942/A_1.scala | 11 +++++++++ tests/pos/t1942/Test_2.scala | 3 +++ tests/pos/t1957.scala | 38 +++++++++++++++++++++++++++++ tests/pos/t1974.scala | 20 +++++++++++++++ tests/pos/t1987a.scala | 8 ++++++ tests/pos/t1987b/a.scala | 7 ++++++ tests/pos/t1987b/b.scala | 10 ++++++++ tests/pos/t1996.scala | 19 +++++++++++++++ 27 files changed, 351 insertions(+) create mode 100644 tests/pos/t160.scala create mode 100644 tests/pos/t1642b.scala create mode 100644 tests/pos/t1659.scala create mode 100644 tests/pos/t1675.scala create mode 100644 tests/pos/t1722-A.scala create mode 100755 tests/pos/t1722/Test.scala create mode 100755 tests/pos/t1722/Top.scala create mode 100644 tests/pos/t175.scala create mode 100644 tests/pos/t177.scala create mode 100644 tests/pos/t1785.scala create mode 100644 tests/pos/t1786-counter.scala create mode 100644 tests/pos/t1786-cycle.scala create mode 100644 tests/pos/t1789.scala create mode 100644 tests/pos/t1798.scala create mode 100644 tests/pos/t183.scala create mode 100644 tests/pos/t1843.scala create mode 100644 tests/pos/t1858.scala create mode 100644 tests/pos/t1896/D0.scala create mode 100644 tests/pos/t1896/D1.scala create mode 100644 tests/pos/t1942/A_1.scala create mode 100644 tests/pos/t1942/Test_2.scala create mode 100644 tests/pos/t1957.scala create mode 100644 tests/pos/t1974.scala create mode 100644 tests/pos/t1987a.scala create mode 100644 tests/pos/t1987b/a.scala create mode 100644 tests/pos/t1987b/b.scala create mode 100644 tests/pos/t1996.scala (limited to 'tests/pos') 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/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 ) +| |-- super EXPRmode-POLYmode-QUALmode (silent: in O) +| | |-- this EXPRmode (silent: in O) +| | | \-> O.type +| | \-> O.type +| |-- (null: Any) match { case (_: LongTraversableLike[(_ @ in O) +| | |-- (null: Any) BYVALmode-EXPRmode (site: value in O) +| | | |-- Any TYPEmode (site: value in O) +| | | | \-> Any +| | | |-- null : pt=Any EXPRmode (site: value in O) +| | | | \-> Null(null) +| | | \-> Any +| | |-- (_: LongTraversableLike[(_ @ )]) : pt=Any PATTERNmode (site: value in O) enrichment only +| | | |-- LongTraversableLike[(_ @ )] TYPEPATmode-TYPEmode (site: value in O) enrichment only +| | | | |-- <: LongTraversableLike[Repr] TYPEmode (site: type Repr in ) +| | | | | |-- LongTraversableLike[Repr] TYPEmode (site: type Repr in ) +| | | | | | |-- Repr NOmode (site: type Repr in ) +| | | | | | | \-> Repr +| | | | | | \-> LongTraversableLike[Repr] +| | | | | [adapt] <: LongTraversableLike[Repr] is now a TypeTree( <: LongTraversableLike[Repr]) +| | | | | \-> <: LongTraversableLike[Repr] +| | | | |-- (_ @ ) TYPEPATmode-TYPEmode (site: value 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/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) + -- cgit v1.2.3