diff options
Diffstat (limited to 'tests')
41 files changed, 421 insertions, 4 deletions
diff --git a/tests/debug/for.scala b/tests/debug/for.scala new file mode 100644 index 000000000..b2287a988 --- /dev/null +++ b/tests/debug/for.scala @@ -0,0 +1,16 @@ +object Test { + def main(args: Array[String]): Unit = { + val b = 8 * 9 // [break] [step: f()] + f() // [step: val a] + 20 + b + print(b) + } + + def f(): Unit = { + val a = for (i <- 1 to 5; j <- 10 to 20) // [cont] + yield (i, j) // Error: incorrect reaching this line + + for (i <- 1 to 5; j <- 10 to 20) + println(i + j) // TODO: i is renamed to i$2 --> reduce debuggability + } +}
\ No newline at end of file diff --git a/tests/debug/function.scala b/tests/debug/function.scala new file mode 100644 index 000000000..644344414 --- /dev/null +++ b/tests/debug/function.scala @@ -0,0 +1,14 @@ +object Test { + def main(args: Array[String]): Unit = { + val a = 1 + 2 + val b = a * 9 // [break] [step: plus] [step: c = plus] + val plus = (x: Int, y: Int) => { // [cont: x * x] + val a = x * x // [break] [step: y * y] + val b = y * y // [step: a + b] + a + b // [next] [next] + } + val c = plus(a, b) // [next: print] + print(c) // [cont] + } + +} diff --git a/tests/debug/if.scala b/tests/debug/if.scala new file mode 100644 index 000000000..af598c1cd --- /dev/null +++ b/tests/debug/if.scala @@ -0,0 +1,20 @@ +object Test { + + def main(args: Array[String]): Unit = { + var a = 1 + 2 // [break] [step: a + 3] + a = a + 3 // [step: 4 + 5] + a = 4 + 5 // [step: if] + + if (a * 8 > 20) // [step: 9 * 9] + a = 9 * 9 // [step: if] + else + a = 34 * 23 + + if (a * 8 < 20) // [step: 34 * 23] + a = 9 * 9 + else + a = 34 * 23 // [step: print] + + print(a) + } +} diff --git a/tests/debug/method.scala b/tests/debug/method.scala new file mode 100644 index 000000000..9489b0088 --- /dev/null +++ b/tests/debug/method.scala @@ -0,0 +1,14 @@ +object Test { + def main(args: Array[String]): Unit = { + val a = 1 + 2 // [break] [step: a * 9] + val b = a * 9 // [step: plus] + val c = plus(a, b) // [step: x * x] + print(c) + } + + def plus(x: Int, y: Int) = { + val a = x * x // [step: y * y] + val b = y * y // [step: a + b] + a + b // [step: plus] [step: print] [cont] + } +} diff --git a/tests/debug/nested-method.scala b/tests/debug/nested-method.scala new file mode 100644 index 000000000..fcc326ccb --- /dev/null +++ b/tests/debug/nested-method.scala @@ -0,0 +1,15 @@ +object Test { + def main(args: Array[String]): Unit = { + val a = 1 + 2 // [break] [step: a * 9] + val b = a * 9 // [step: plus] [step: x * x] + + def plus(x: Int, y: Int) = { + val a = x * x // [step: y * y] + val b = y * y // [step: a + b] + a + b // [step: plus] + } + + val c = plus(a, b) // [step: print] [cont] + print(c) + } +}
\ No newline at end of file diff --git a/tests/debug/sequence.scala b/tests/debug/sequence.scala new file mode 100644 index 000000000..a6c1e9018 --- /dev/null +++ b/tests/debug/sequence.scala @@ -0,0 +1,11 @@ +object Test { + def main(args: Array[String]): Unit = { + var a = 1 + 2 // [break] [step: a + 3] + a = a + 3 // [step: 4 + 5] + a = 4 + 5 // [step: a * 8] + a = a * 8 // [step: 9 * 9] + a = 9 * 9 // [step: 34 * 23] + a = 34 * 23 // [step: print] + print(a) // [cont] + } +}
\ No newline at end of file diff --git a/tests/debug/tailrec.scala b/tests/debug/tailrec.scala new file mode 100644 index 000000000..f79514fa3 --- /dev/null +++ b/tests/debug/tailrec.scala @@ -0,0 +1,17 @@ +object Test { + def fact(x: Int): Int = { + if (x == 0) + 1 + else + x * fact(x - 1) // TODO: incorrect this line when x = 0 + } + + + def main(args: Array[String]): Unit = { + val a = 1 + 2 + val b = a * 9 // [break] [step: fact] + val c = fact(a) // [step: x == 0] [step: fact(x - 1)] [step: x == 0] [cont] + fact(0) // [break] [step: x == 0] [step: 1] [step: fact(x - 1)] [step: print] + print(c) // [cont] + } +}
\ No newline at end of file diff --git a/tests/debug/while.scala b/tests/debug/while.scala new file mode 100644 index 000000000..0e5f8f8b0 --- /dev/null +++ b/tests/debug/while.scala @@ -0,0 +1,14 @@ +object Test { + + def main(args: Array[String]): Unit = { + var a = 1 + 2 + a = a + 3 + a = 4 + 5 // [break] [step: while] + + while (a * 8 < 100) { // [step: a += 1] + a += 1 // [step: while] [cont: print] + } + + print(a) // [break] [cont] + } +} diff --git a/tests/neg/selfreq.scala b/tests/disabled/scalac-dependent/neg/selfreq.scala index 1ca373b4b..1ca373b4b 100644 --- a/tests/neg/selfreq.scala +++ b/tests/disabled/scalac-dependent/neg/selfreq.scala diff --git a/tests/pos-special/i859.scala b/tests/disabled/scalac-dependent/pos-special/i859.scala index a9f6b51c9..a9f6b51c9 100644 --- a/tests/pos-special/i859.scala +++ b/tests/disabled/scalac-dependent/pos-special/i859.scala diff --git a/tests/pos/t5604/ReplConfig.scala b/tests/disabled/scalac-dependent/pos/t5604/ReplConfig.scala index 8c589eba6..8c589eba6 100644 --- a/tests/pos/t5604/ReplConfig.scala +++ b/tests/disabled/scalac-dependent/pos/t5604/ReplConfig.scala diff --git a/tests/pos/t5604/ReplReporter.scala b/tests/disabled/scalac-dependent/pos/t5604/ReplReporter.scala index 9423efd8a..9423efd8a 100644 --- a/tests/pos/t5604/ReplReporter.scala +++ b/tests/disabled/scalac-dependent/pos/t5604/ReplReporter.scala diff --git a/tests/pos/t5899.scala b/tests/disabled/scalac-dependent/pos/t5899.scala index 852b4e3e7..852b4e3e7 100644 --- a/tests/pos/t5899.scala +++ b/tests/disabled/scalac-dependent/pos/t5899.scala diff --git a/tests/pos/t7591.scala b/tests/disabled/scalac-dependent/pos/t7591.scala index dd127b881..dd127b881 100644 --- a/tests/pos/t7591.scala +++ b/tests/disabled/scalac-dependent/pos/t7591.scala diff --git a/tests/pos/trait-force-info.scala b/tests/disabled/scalac-dependent/pos/trait-force-info.scala index c2b33869c..c2b33869c 100644 --- a/tests/pos/trait-force-info.scala +++ b/tests/disabled/scalac-dependent/pos/trait-force-info.scala diff --git a/tests/run/t1618.scala b/tests/disabled/scalac-dependent/run/t1618.scala index 248af9b4f..248af9b4f 100644 --- a/tests/run/t1618.scala +++ b/tests/disabled/scalac-dependent/run/t1618.scala diff --git a/tests/run/t7775.scala b/tests/disabled/scalac-dependent/run/t7775.scala index bc6a67d0e..bc6a67d0e 100644 --- a/tests/run/t7775.scala +++ b/tests/disabled/scalac-dependent/run/t7775.scala diff --git a/tests/neg/customArgs/cliError.scala b/tests/neg/customArgs/cliError.scala deleted file mode 100644 index b2f0f6cdc..000000000 --- a/tests/neg/customArgs/cliError.scala +++ /dev/null @@ -1,2 +0,0 @@ -// nopos-error -object Test diff --git a/tests/neg/customArgs/i2002.scala b/tests/neg/customArgs/i2002.scala new file mode 100644 index 000000000..5561b77b8 --- /dev/null +++ b/tests/neg/customArgs/i2002.scala @@ -0,0 +1,4 @@ +class Test { + def foo(i: Int): Int = i + def foo(implicit i: Int): Int = i // error +} diff --git a/tests/neg/i1501.scala b/tests/neg/i1501.scala new file mode 100644 index 000000000..685566403 --- /dev/null +++ b/tests/neg/i1501.scala @@ -0,0 +1,28 @@ +class A { + def foo: Int = 1 +} + +trait B extends A + +abstract class D { + def foo: Int +} + +class C extends D with B // error: illegal trait inheritance +trait E extends D with B // error: illegal trait inheritance + +object Test { + def main(args: Array[String]): Unit = { + println(new C().foo) + } +} + +object Test2 { + class A + class SubA(x: Int) extends A + trait TA extends A + trait TSubA extends SubA(2) // error: trait TSubA may not call constructor of class SubA + + + class Foo extends TA with TSubA // error: missing argument for parameter x of constructor SubA: +} diff --git a/tests/neg/i1653.scala b/tests/neg/i1653.scala index ab5369e5f..f21fc7d54 100644 --- a/tests/neg/i1653.scala +++ b/tests/neg/i1653.scala @@ -1,3 +1,3 @@ trait Foo { - def foo() = new Unit with Foo // error + def foo() = new Unit with Foo // error: cannot extend final class Unit // error: illegal trait inheritance } diff --git a/tests/neg/i1747.scala b/tests/neg/i1747.scala new file mode 100644 index 000000000..54492aaed --- /dev/null +++ b/tests/neg/i1747.scala @@ -0,0 +1,3 @@ +class Coll[E] extends java.util.Collection[E] { // error: needs to be abstract + def toArray[T](a: Array[T]): Array[T] = ??? // error: cannot override +} diff --git a/tests/neg/i1992.scala b/tests/neg/i1992.scala new file mode 100644 index 000000000..818b46771 --- /dev/null +++ b/tests/neg/i1992.scala @@ -0,0 +1,9 @@ +object Test { + def main(args: Array[String]) = { + val x: Int => Unit = + y => println(x) // error: `x` is a forward reference + implicit val z: String => Unit = + y => println(implicitly[String => Unit]) // error: `z` is a forward reference + } +} + diff --git a/tests/neg/i2000.scala b/tests/neg/i2000.scala new file mode 100644 index 000000000..aa1250f08 --- /dev/null +++ b/tests/neg/i2000.scala @@ -0,0 +1,23 @@ +object test1 { + class C[A] { def foo(a: A) = "c" } + class D extends C[String] { override def foo(implicit s: String) = "d" } // error +} + +object test2 { + class C[A] { final def foo(a: A) = "c" } + class D extends C[String] { def foo(implicit s: String) = "d" } // error + object Test { + def main(args: Array[String]) = + new D + } +} + +object test3 { + class A { + def foo(implicit i: Int): Int = i + i + } + + class B extends A { + override def foo(i: Int): Int = i // error + } +} diff --git a/tests/neg/i2001.scala b/tests/neg/i2001.scala new file mode 100644 index 000000000..82518890c --- /dev/null +++ b/tests/neg/i2001.scala @@ -0,0 +1,6 @@ +class A { + def odd(x: Int) = if (x == 0) false else !even(x-1) + def even(x: Int) = if (x == 0) true else !odd(x-1) // error: overloaded or recursive method needs result type + + lazy val x = x // error: recursive value needs type +} diff --git a/tests/neg/i2005.scala b/tests/neg/i2005.scala new file mode 100644 index 000000000..fc2e4ddec --- /dev/null +++ b/tests/neg/i2005.scala @@ -0,0 +1,7 @@ + +object Test { + val a = 42 + def main(args: Array[String]) = { + val a: Int = a // error + } +} diff --git a/tests/neg/i2006.scala b/tests/neg/i2006.scala new file mode 100644 index 000000000..f1b48b011 --- /dev/null +++ b/tests/neg/i2006.scala @@ -0,0 +1,10 @@ +object Test { + + inline def foo(f: ImplicitFunction1[Int, Int]): AnyRef = f // error + inline def bar(f: ImplicitFunction1[Int, Int]) = f // error + + def main(args: Array[String]) = { + foo(implicit thisTransaction => 43) + bar(implicit thisTransaction => 44) + } +} diff --git a/tests/pos/i1975.scala b/tests/pos/i1975.scala new file mode 100644 index 000000000..4657a6735 --- /dev/null +++ b/tests/pos/i1975.scala @@ -0,0 +1,5 @@ +object Test { + val X = Seq(1, 2) + + for (X <- Seq(3, 4)) yield println(X) +} diff --git a/tests/pos/i1976.scala b/tests/pos/i1976.scala new file mode 100644 index 000000000..32967977d --- /dev/null +++ b/tests/pos/i1976.scala @@ -0,0 +1,4 @@ +object Test { + import scala.xml._ + val node = <node>{ "whatever " }</node> +} diff --git a/tests/pos/i1990.scala b/tests/pos/i1990.scala new file mode 100644 index 000000000..77cea0af7 --- /dev/null +++ b/tests/pos/i1990.scala @@ -0,0 +1,12 @@ +class A { + class Foo { + inline def inlineMeth: Unit = { + new Bar + } + } + class Bar +} + +class B extends A { + (new Foo).inlineMeth +} diff --git a/tests/pos/i1990a.scala b/tests/pos/i1990a.scala new file mode 100644 index 000000000..f6f95ee36 --- /dev/null +++ b/tests/pos/i1990a.scala @@ -0,0 +1,20 @@ +class A { self => + class Foo { + inline def inlineMeth: Unit = { + println(self) + } + } +} + +class C extends A { + class B extends A +} + +object Test { + def main(args: Array[String]): Unit = { + val c = new C + val b = new c.B + + (new b.Foo).inlineMeth + } +} diff --git a/tests/pos/i2009.scala b/tests/pos/i2009.scala new file mode 100644 index 000000000..e2cf47203 --- /dev/null +++ b/tests/pos/i2009.scala @@ -0,0 +1,9 @@ +object Test { + + trait Gen[T] { + def map[U](f: T => U): Gen[U] = ??? + } + + def f[T](implicit g: Gen[T]): Gen[() => T] = + g map ( () => _ ) +} diff --git a/tests/pos/inferOverloaded.scala b/tests/pos/inferOverloaded.scala new file mode 100644 index 000000000..e7179a04a --- /dev/null +++ b/tests/pos/inferOverloaded.scala @@ -0,0 +1,41 @@ +class MySeq[T] { + def map1[U](f: T => U): MySeq[U] = new MySeq[U] + def map2[U](f: T => U): MySeq[U] = new MySeq[U] +} + +class MyMap[A, B] extends MySeq[(A, B)] { + def map1[C](f: (A, B) => C): MySeq[C] = new MySeq[C] + def map1[C, D](f: (A, B) => (C, D)): MyMap[C, D] = new MyMap[C, D] + def map1[C, D](f: ((A, B)) => (C, D)): MyMap[C, D] = new MyMap[C, D] + + def foo(f: Function2[Int, Int, Int]): Unit = () + def foo[R](pf: PartialFunction[(A, B), R]): MySeq[R] = new MySeq[R] +} + +object Test { + val m = new MyMap[Int, String] + + // This one already worked because it is not overloaded: + m.map2 { case (k, v) => k - 1 } + + // These already worked because preSelectOverloaded eliminated the non-applicable overload: + m.map1(t => t._1) + m.map1((kInFunction, vInFunction) => kInFunction - 1) + val r1 = m.map1(t => (t._1, 42.0)) + val r1t: MyMap[Int, Double] = r1 + + // These worked because the argument types are known for overload resolution: + m.map1({ case (k, v) => k - 1 }: PartialFunction[(Int, String), Int]) + m.map2({ case (k, v) => k - 1 }: PartialFunction[(Int, String), Int]) + + // These ones did not work before: + m.map1 { case (k, v) => k } + val r = m.map1 { case (k, v) => (k, k*10) } + val rt: MyMap[Int, Int] = r + m.foo { case (k, v) => k - 1 } + + // Used to be ambiguous but overload resolution now favors PartialFunction + def h[R](pf: Function2[Int, String, R]): Unit = () + def h[R](pf: PartialFunction[(Double, Double), R]): Unit = () + h { case (a: Double, b: Double) => 42: Int } +} diff --git a/tests/repl/errmsgs.check b/tests/repl/errmsgs.check index 0dc8e8ae5..d7a230e61 100644 --- a/tests/repl/errmsgs.check +++ b/tests/repl/errmsgs.check @@ -85,4 +85,11 @@ scala> val x: List[Int] = "foo" :: List(1) | found: String($1$) | required: Int | +scala> { def f: Int = g; val x: Int = 1; def g: Int = 5; } +-- [E039] Reference Error: <console> ------------------------------------------- +5 |{ def f: Int = g; val x: Int = 1; def g: Int = 5; } + | ^ + | `g` is a forward reference extending over the definition of `x` + +longer explanation available when compiling with `-explain` scala> :quit diff --git a/tests/repl/imports.check b/tests/repl/imports.check index 5260589a9..345fac142 100644 --- a/tests/repl/imports.check +++ b/tests/repl/imports.check @@ -11,7 +11,7 @@ scala> buf += xs 11 |buf += xs | ^^ | found: scala.collection.immutable.List[Int](o.xs) - | required: String + | required: Int | scala> buf ++= xs val res1: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3) diff --git a/tests/run/builder.check b/tests/run/builder.check new file mode 100644 index 000000000..48f7d9253 --- /dev/null +++ b/tests/run/builder.check @@ -0,0 +1 @@ +Table(Row(Cell(A1), Cell(B1)), Row(Cell(A2), Cell(B2))) diff --git a/tests/run/builder.scala b/tests/run/builder.scala new file mode 100644 index 000000000..532a95071 --- /dev/null +++ b/tests/run/builder.scala @@ -0,0 +1,51 @@ +import collection.mutable.ArrayBuffer + +class Table { + val rows = new ArrayBuffer[Row] + def add(r: Row): Unit = rows += r + override def toString = rows.mkString("Table(", ", ", ")") +} + +class Row { + val cells = new ArrayBuffer[Cell] + def add(c: Cell): Unit = cells += c + override def toString = cells.mkString("Row(", ", ", ")") +} + +class Cell(elem: String) { + override def toString = s"Cell($elem)" +} + +object Test { + + def table(init: implicit Table => Unit) = { + implicit val t = new Table + init + t + } + + def row(init: implicit Row => Unit)(implicit t: Table) = { + implicit val r = new Row + init + t.add(r) + } + + def cell(str: String)(implicit r: Row) = + r.add(new Cell(str)) + + val data = + table { + row { + cell("A1") + cell("B1") + } + row { + cell("A2") + cell("B2") + } + } + + def main(args: Array[String]) = { + println(data) + } +} diff --git a/tests/run/i1990b.check b/tests/run/i1990b.check new file mode 100644 index 000000000..dd84bc9fb --- /dev/null +++ b/tests/run/i1990b.check @@ -0,0 +1 @@ +C() diff --git a/tests/run/i1990b.scala b/tests/run/i1990b.scala new file mode 100644 index 000000000..2460208db --- /dev/null +++ b/tests/run/i1990b.scala @@ -0,0 +1,20 @@ +trait A { self => + class Foo { + inline def inlineMeth: Unit = { + println(self) + } + } +} + +case class A2() extends A { + case class C() extends Foo with A + + val c = new C + (new c.Foo).inlineMeth +} + +object Test { + def main(args: Array[String]): Unit = { + new A2 + } +} diff --git a/tests/run/i1991.scala b/tests/run/i1991.scala new file mode 100644 index 000000000..cec1dec89 --- /dev/null +++ b/tests/run/i1991.scala @@ -0,0 +1,29 @@ +import scala.reflect.ClassTag + +class A[Foo](implicit tag: ClassTag[Foo]) { + object ExtractFoo { + def unapply(foo: Foo): Boolean = true + } + + def isFoo(x: Any) = x match { + case ExtractFoo() => true + //case foo: Foo => true + case _ => false + } + + def testBind(x: Any) = x match { + case foo0: Foo => + (foo0: Foo) + case foo1 @ (_: Foo) => + (foo1: Foo) + case foo2 @ ExtractFoo() => + (foo2: Foo) + } +} + +object Test { + def main(args: Array[String]): Unit = { + assert((new A[String]).isFoo("foo")) // OK + assert(!(new A[String]).isFoo(42)) // OK in scalac, fails in Dotty + } +} diff --git a/tests/run/i2020.scala b/tests/run/i2020.scala new file mode 100644 index 000000000..78794a590 --- /dev/null +++ b/tests/run/i2020.scala @@ -0,0 +1,8 @@ +object Test { + + case class Foo(x: Int)(y: Int) + + def main(args: Array[String]) = + assert(Foo(1)(1) == Foo(1)(2)) + +} |