aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/i2142.scala28
-rw-r--r--tests/patmat/enum-HList.scala22
-rw-r--r--tests/patmat/enum-Tree.scala29
-rw-r--r--tests/patmat/enumColor.scala12
-rw-r--r--tests/patmat/patmat-indent.check2
-rw-r--r--tests/patmat/patmat-indent.scala2
-rw-r--r--tests/patmat/planets.scala26
-rw-r--r--tests/patmat/t6420.check2
-rw-r--r--tests/patmat/t7285.check2
-rw-r--r--tests/patmat/t7466.check2
-rw-r--r--tests/pickling/i2166.scala5
-rw-r--r--tests/pos/i2188.scala5
-rw-r--r--tests/pos/i2192.scala7
-rw-r--r--tests/pos/i2198.scala6
-rw-r--r--tests/pos/i2200/Hello.scala6
-rw-r--r--tests/pos/i2200/package.scala4
-rw-r--r--tests/pos/i2201a.scala8
-rw-r--r--tests/pos/i2201b.scala14
-rw-r--r--tests/pos/i2201c.scala11
-rw-r--r--tests/run/enum-Color.scala4
20 files changed, 192 insertions, 5 deletions
diff --git a/tests/neg/i2142.scala b/tests/neg/i2142.scala
new file mode 100644
index 000000000..7aeef95f0
--- /dev/null
+++ b/tests/neg/i2142.scala
@@ -0,0 +1,28 @@
+object Foo {
+
+class A
+val a1 = new A()
+val a2 = new A()
+
+def f(x: A, y: x.type) = ()
+f(a1, a1) // ok
+f(a1, a2) // error
+f(new A(), new A()) // error
+f(new A(), a1) // error
+
+def g(x: A)(y: x.type) = ()
+g(a1)(a1) // ok
+g(a1)(a2) // error
+g(new A())(new A()) // error
+g(new A())(a1) // error
+
+val x0 = g(new A()) _
+x0 (new A()) // error
+
+class C[T]
+
+def h(x: A): C[x.type] = ???
+val x = h(a1)
+val y = h(new A())
+
+}
diff --git a/tests/patmat/enum-HList.scala b/tests/patmat/enum-HList.scala
new file mode 100644
index 000000000..c019cb6cc
--- /dev/null
+++ b/tests/patmat/enum-HList.scala
@@ -0,0 +1,22 @@
+enum HLst {
+ case HCons[+Hd, +Tl <: HLst](hd: Hd, tl: Tl)
+ case HNil
+}
+
+object Test {
+ import HLst._
+ def length(hl: HLst): Int = hl match {
+ case HCons(_, tl) => 1 + length(tl)
+ case HNil => 0
+ }
+ def sumInts(hl: HLst): Int = hl match {
+ case HCons(x: Int, tl) => x + sumInts(tl)
+ case HCons(_, tl) => sumInts(tl)
+ case HNil => 0
+ }
+ def main(args: Array[String]) = {
+ val hl = HCons(1, HCons("A", HNil))
+ assert(length(hl) == 2, length(hl))
+ assert(sumInts(hl) == 1)
+ }
+}
diff --git a/tests/patmat/enum-Tree.scala b/tests/patmat/enum-Tree.scala
new file mode 100644
index 000000000..ef5bd7a57
--- /dev/null
+++ b/tests/patmat/enum-Tree.scala
@@ -0,0 +1,29 @@
+enum Tree[T] {
+ case True extends Tree[Boolean]
+ case False extends Tree[Boolean]
+ case Zero extends Tree[Int]
+ case Succ(n: Tree[Int]) extends Tree[Int]
+ case Pred(n: Tree[Int]) extends Tree[Int]
+ case IsZero(n: Tree[Int]) extends Tree[Boolean]
+ case If(cond: Tree[Boolean], thenp: Tree[T], elsep: Tree[T])
+}
+
+object Test {
+ import Tree._
+
+ def eval[T](e: Tree[T]): T = e match {
+ case True => true
+ case False => false
+ case Zero => 0
+ case Succ(f) => eval(f) + 1
+ case Pred(f) => eval(f) - 1
+ case IsZero(f) => eval(f) == 0
+ case If(cond, thenp, elsep) => if (eval(cond)) eval(thenp) else eval(elsep)
+ }
+
+ val data = If(IsZero(Pred(Succ(Zero))), Succ(Succ(Zero)), Pred(Pred(Zero)))
+
+ def main(args: Array[String]) = {
+ println(s"$data --> ${eval(data)}")
+ }
+}
diff --git a/tests/patmat/enumColor.scala b/tests/patmat/enumColor.scala
new file mode 100644
index 000000000..60d610d0d
--- /dev/null
+++ b/tests/patmat/enumColor.scala
@@ -0,0 +1,12 @@
+ enum Color {
+ case Red, Green, Blue
+ }
+
+ object Test {
+ def f(color: Color) = {
+ import Color._
+ color match {
+ case Red | Green | Blue =>
+ }
+ }
+}
diff --git a/tests/patmat/patmat-indent.check b/tests/patmat/patmat-indent.check
index 79845ebcf..4f0ec4dd9 100644
--- a/tests/patmat/patmat-indent.check
+++ b/tests/patmat/patmat-indent.check
@@ -1,3 +1,3 @@
9: Pattern Match Exhaustivity: Nil
-23: Pattern Match Exhaustivity: _: Boolean
+23: Pattern Match Exhaustivity: true, false
27: Pattern Match Exhaustivity: _: Int
diff --git a/tests/patmat/patmat-indent.scala b/tests/patmat/patmat-indent.scala
index ef25bb2c7..a2b18e7fb 100644
--- a/tests/patmat/patmat-indent.scala
+++ b/tests/patmat/patmat-indent.scala
@@ -1,5 +1,5 @@
object Test {
- val Nil = scala.Nil
+ val Nil: scala.collection.immutable.Nil.type = scala.collection.immutable.Nil
val X = 5
object Inner {
diff --git a/tests/patmat/planets.scala b/tests/patmat/planets.scala
new file mode 100644
index 000000000..bcbfd7eeb
--- /dev/null
+++ b/tests/patmat/planets.scala
@@ -0,0 +1,26 @@
+enum class Planet(mass: Double, radius: Double) {
+ private final val G = 6.67300E-11
+ def surfaceGravity = G * mass / (radius * radius)
+ def surfaceWeight(otherMass: Double) = otherMass * surfaceGravity
+}
+object Planet {
+ case MERCURY extends Planet(3.303e+23, 2.4397e6)
+ case VENUS extends Planet(4.869e+24, 6.0518e6)
+ case EARTH extends Planet(5.976e+24, 6.37814e6)
+ case MARS extends Planet(6.421e+23, 3.3972e6)
+ case JUPITER extends Planet(1.9e+27, 7.1492e7)
+ case SATURN extends Planet(5.688e+26, 6.0268e7)
+ case URANUS extends Planet(8.686e+25, 2.5559e7)
+ case NEPTUNE extends Planet(1.024e+26, 2.4746e7)
+}
+object Test {
+ def main(args: Array[String]) = {
+ import Planet._
+ assert(enumValueNamed("SATURN") == SATURN)
+ assert(enumValue(2) == EARTH)
+ val earthWeight = 100
+ val mass = earthWeight/EARTH.surfaceGravity
+ for (p <- enumValues)
+ println(s"Your weight on $p is ${p.surfaceWeight(mass)}")
+ }
+}
diff --git a/tests/patmat/t6420.check b/tests/patmat/t6420.check
index 73acf1454..c15701594 100644
--- a/tests/patmat/t6420.check
+++ b/tests/patmat/t6420.check
@@ -1 +1 @@
-5: Pattern Match Exhaustivity: (Nil, _), (List(_, _), _), (Nil, Nil), (Nil, List(_, _)), (List(_, _), Nil), (List(_, _), List(_, _)), (_, Nil), (_, List(_, _))
+5: Pattern Match Exhaustivity: (Nil, _), (List(true, _), _), (List(false, _), _), (_, Nil), (_, List(true, _)), (_, List(false, _))
diff --git a/tests/patmat/t7285.check b/tests/patmat/t7285.check
index 1c2841920..d40b77e4b 100644
--- a/tests/patmat/t7285.check
+++ b/tests/patmat/t7285.check
@@ -1,3 +1,3 @@
15: Pattern Match Exhaustivity: (Up, Down)
33: Pattern Match Exhaustivity: Down
-51: Pattern Match Exhaustivity: (Base.Up, Base.Down)
+51: Pattern Match Exhaustivity: (Up, Down)
diff --git a/tests/patmat/t7466.check b/tests/patmat/t7466.check
index 35227484e..af596399b 100644
--- a/tests/patmat/t7466.check
+++ b/tests/patmat/t7466.check
@@ -1 +1 @@
-8: Pattern Match Exhaustivity: (_, _)
+8: Pattern Match Exhaustivity: (true, _), (false, _), (_, true), (_, false)
diff --git a/tests/pickling/i2166.scala b/tests/pickling/i2166.scala
new file mode 100644
index 000000000..7199b7a36
--- /dev/null
+++ b/tests/pickling/i2166.scala
@@ -0,0 +1,5 @@
+object Test {
+ @inline def f = "" match { case _ => false }
+
+ def main(args: Array[String]): Unit = f
+} \ No newline at end of file
diff --git a/tests/pos/i2188.scala b/tests/pos/i2188.scala
new file mode 100644
index 000000000..4129977ac
--- /dev/null
+++ b/tests/pos/i2188.scala
@@ -0,0 +1,5 @@
+class Fill(elem: => Int) {
+ class Iter {
+ def next(): Int = elem
+ }
+}
diff --git a/tests/pos/i2192.scala b/tests/pos/i2192.scala
new file mode 100644
index 000000000..2e85e366e
--- /dev/null
+++ b/tests/pos/i2192.scala
@@ -0,0 +1,7 @@
+object Test {
+ def foo(x: Int): Int = x
+
+ Some(foo): Option[Int => Int]
+ // missing arguments for method foo
+ // follow this method with `_' if you want to treat it as a partially applied function
+}
diff --git a/tests/pos/i2198.scala b/tests/pos/i2198.scala
new file mode 100644
index 000000000..62ae7e8b5
--- /dev/null
+++ b/tests/pos/i2198.scala
@@ -0,0 +1,6 @@
+object Test {
+ val nil = scala.collection.immutable.Nil
+ def f(x: nil.type): Int = 3
+
+ f(scala.collection.immutable.Nil)
+}
diff --git a/tests/pos/i2200/Hello.scala b/tests/pos/i2200/Hello.scala
new file mode 100644
index 000000000..47e8b2024
--- /dev/null
+++ b/tests/pos/i2200/Hello.scala
@@ -0,0 +1,6 @@
+package bar
+import scala.language.higherKinds
+class Fix[F[_]](unfix: F[Fix[F]])
+object DocTree {
+ def docTree(s: StreamTree[DocTree]): DocTree = new Fix(s: StreamTree[DocTree])
+}
diff --git a/tests/pos/i2200/package.scala b/tests/pos/i2200/package.scala
new file mode 100644
index 000000000..3bc519b72
--- /dev/null
+++ b/tests/pos/i2200/package.scala
@@ -0,0 +1,4 @@
+package object bar {
+ type StreamTree[T] = Stream[Int]
+ type DocTree = Fix[StreamTree]
+}
diff --git a/tests/pos/i2201a.scala b/tests/pos/i2201a.scala
new file mode 100644
index 000000000..165f0a76e
--- /dev/null
+++ b/tests/pos/i2201a.scala
@@ -0,0 +1,8 @@
+class Foo[T]
+
+class Fix[F[_]](unfix: F[Fix[F]])
+object DocTree {
+ type Const[T] = Foo[Int]
+ type FixConst = Fix[Const]
+ def docTree(s: Const[FixConst]): FixConst = new Fix(s)
+}
diff --git a/tests/pos/i2201b.scala b/tests/pos/i2201b.scala
new file mode 100644
index 000000000..4aafc0d28
--- /dev/null
+++ b/tests/pos/i2201b.scala
@@ -0,0 +1,14 @@
+trait X
+trait Y
+
+object Test {
+ type One[A <: X, B <: Y]
+
+ type Two[TA <: Y, TB <: X] = One[TB, TA]
+
+ def foo[M[_ <: Y, _ <: X]](x: M[_ <: Y, _ <: X]) = x
+
+ val a: Two[Y, X] = ???
+
+ foo(a)
+}
diff --git a/tests/pos/i2201c.scala b/tests/pos/i2201c.scala
new file mode 100644
index 000000000..91f2529d9
--- /dev/null
+++ b/tests/pos/i2201c.scala
@@ -0,0 +1,11 @@
+object Test {
+ implicit val theAnswer: Int = 42
+
+ type Swap[A, B] = (B, A)
+
+ def foo[M[_, _], T, S](x: M[T, S])(implicit ev: T) = ev
+
+ val a: Swap[Int, String] = ("hi", 1)
+
+ foo(a)
+}
diff --git a/tests/run/enum-Color.scala b/tests/run/enum-Color.scala
index 683d18d9e..f4f6aaef8 100644
--- a/tests/run/enum-Color.scala
+++ b/tests/run/enum-Color.scala
@@ -7,5 +7,9 @@ object Test {
for (color <- Color.enumValues) {
println(s"$color: ${color.enumTag}")
assert(Color.enumValue(color.enumTag) eq color)
+ import Color._
+ color match {
+ case Red | Green | Blue =>
+ }
}
}