aboutsummaryrefslogtreecommitdiff
path: root/tests/pos
diff options
context:
space:
mode:
Diffstat (limited to 'tests/pos')
-rw-r--r--tests/pos/Monoid.scala61
-rw-r--r--tests/pos/Patterns.scala28
-rw-r--r--tests/pos/functionXXL.scala72
-rw-r--r--tests/pos/hkwild.scala6
-rw-r--r--tests/pos/i1540.scala4
-rw-r--r--tests/pos/i1540b.scala4
-rw-r--r--tests/pos/i1642.scala2
-rw-r--r--tests/pos/i1665.scala7
-rw-r--r--tests/pos/i1704.scala4
-rw-r--r--tests/pos/i1737.scala11
-rw-r--r--tests/pos/i1751.scala17
-rw-r--r--tests/pos/i1753.scala22
-rw-r--r--tests/pos/i1755.scala21
-rw-r--r--tests/pos/i1756.scala20
-rw-r--r--tests/pos/i1757.scala6
-rw-r--r--tests/pos/i1765.scala21
-rw-r--r--tests/pos/i1776.scala3
-rw-r--r--tests/pos/i1777.scala9
-rw-r--r--tests/pos/i1786.scala18
-rw-r--r--tests/pos/i1790.scala15
-rw-r--r--tests/pos/i1793.scala7
-rw-r--r--tests/pos/i1795.scala13
-rw-r--r--tests/pos/i1797.scala1
-rw-r--r--tests/pos/i1803.scala7
-rw-r--r--tests/pos/i1812.scala12
-rw-r--r--tests/pos/i1812b.scala11
-rw-r--r--tests/pos/i1865.scala24
-rw-r--r--tests/pos/i1867.scala3
-rw-r--r--tests/pos/i1868.scala7
-rw-r--r--tests/pos/i1891.scala11
-rw-r--r--tests/pos/implicits.scala5
-rw-r--r--tests/pos/lazyValsSepComp.scala2
-rw-r--r--tests/pos/pos_valueclasses/optmatch.scala2
33 files changed, 450 insertions, 6 deletions
diff --git a/tests/pos/Monoid.scala b/tests/pos/Monoid.scala
new file mode 100644
index 000000000..f6004cdf3
--- /dev/null
+++ b/tests/pos/Monoid.scala
@@ -0,0 +1,61 @@
+package strawman.typeclasses
+
+trait SemiGroup[T] {
+ def append(x: T, y: T): T
+}
+object SemiGroup {
+ class Ops {
+ implicit class InfixAppend[T: SemiGroup](self: T) {
+ def |+| (other: T): T = implicitly[SemiGroup[T]].append(self, other)
+ }
+ }
+ object ops extends Ops
+}
+
+trait Monoid[T] extends SemiGroup[T] {
+ val id: T
+}
+object Monoid {
+ object ops extends SemiGroup.Ops
+}
+
+trait Ring[T] extends Monoid[T] {
+ val zero = id
+ val one: T
+ def product(x: T, y: T): T
+}
+object Ring {
+ class Ops extends SemiGroup.Ops {
+ implicit class InfixProduct[T: Ring](self: T) {
+ def |*| (other: T): T = implicitly[Ring[T]].product(self, other)
+ }
+ }
+ object ops extends Ops
+}
+
+
+
+object Test {
+ implicit object StringMonoid extends Monoid[String] {
+ def append(x: String, y: String): String = x ++ y
+ val id = ""
+ }
+
+ implicit object IntRing extends Ring[Int] {
+ def append(x: Int, y: Int) = x + y
+ val id = 0
+ val one = 1
+ def product(x: Int, y: Int) = x * y
+ }
+
+ import Monoid.ops._ // works in dotty, fails in scalac
+ import Ring.ops._
+ "abc" |+| "def"
+ "abc" |+| StringMonoid.id
+ StringMonoid.id |+| "abc"
+
+ 1 |+| 2
+ 3 |*| 3
+
+
+}
diff --git a/tests/pos/Patterns.scala b/tests/pos/Patterns.scala
index aa369a77b..fd0d7e97a 100644
--- a/tests/pos/Patterns.scala
+++ b/tests/pos/Patterns.scala
@@ -108,3 +108,31 @@ object NestedPattern {
val xss: List[List[String]] = ???
val List(List(x)) = xss
}
+
+// Tricky case (exercised by Scala parser combinators) where we use
+// both get/isEmpty and product-based pattern matching in different
+// matches on the same types.
+object ProductAndGet {
+
+ trait Result[+T]
+ case class Success[+T](in: String, x: T) extends Result[T] {
+ def isEmpty = false
+ def get: T = x
+ }
+ case class Failure[+T](in: String, msg: String) extends Result[T] {
+ def isEmpty = false
+ def get: String = msg
+ }
+
+ val r: Result[Int] = ???
+
+ r match {
+ case Success(in, x) => x
+ case Failure(in, msg) => -1
+ }
+
+ r match {
+ case Success(x) => x
+ case Failure(msg) => -1
+ }
+}
diff --git a/tests/pos/functionXXL.scala b/tests/pos/functionXXL.scala
new file mode 100644
index 000000000..1063e4170
--- /dev/null
+++ b/tests/pos/functionXXL.scala
@@ -0,0 +1,72 @@
+object Test {
+
+ val f = (x1: Int,
+ x2: Int,
+ x3: Int,
+ x4: Int,
+ x5: Int,
+ x6: Int,
+ x7: Int,
+ x8: Int,
+ x9: Int,
+ x10: Int,
+ x11: Int,
+ x12: Int,
+ x13: Int,
+ x14: Int,
+ x15: Int,
+ x16: Int,
+ x17: Int,
+ x18: Int,
+ x19: Int,
+ x20: Int,
+ x21: Int,
+ x22: Int,
+ x23: Int,
+ x24: Int,
+ x25: Int,
+ x26: Int) => 42
+
+ def main(args: Array[String]) = {
+ val g = (x1: Int,
+ x2: Int,
+ x3: Int,
+ x4: Int,
+ x5: Int,
+ x6: Int,
+ x7: Int,
+ x8: Int,
+ x9: Int,
+ x10: Int,
+ x11: Int,
+ x12: Int,
+ x13: Int,
+ x14: Int,
+ x15: Int,
+ x16: Int,
+ x17: Int,
+ x18: Int,
+ x19: Int,
+ x20: Int,
+ x21: Int,
+ x22: Int,
+ x23: Int,
+ x24: Int,
+ x25: Int,
+ x26: Int) => f(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10,
+ x11, x12, x13, x14, x15, x16, x17, x18, x19, x20,
+ x21, x22, x23, x24, x25, x26)
+
+
+
+ println(f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26))
+
+
+ println(g(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26))
+ }
+
+}
diff --git a/tests/pos/hkwild.scala b/tests/pos/hkwild.scala
new file mode 100644
index 000000000..49bea7d01
--- /dev/null
+++ b/tests/pos/hkwild.scala
@@ -0,0 +1,6 @@
+class Test[T1](val x: T1) {
+ def invert[El1, CC1[X]](implicit w1: T1 <:< CC1[El1]) = {
+ val buf: CC1[_] = w1(x)
+ ???
+ }
+}
diff --git a/tests/pos/i1540.scala b/tests/pos/i1540.scala
index 7aa24f459..0fdfea235 100644
--- a/tests/pos/i1540.scala
+++ b/tests/pos/i1540.scala
@@ -1,6 +1,6 @@
class Casey1(val a: Int) {
- def isDefined: Boolean = true
- def isDefined(x: Int): Boolean = ???
+ def isEmpty: Boolean = false
+ def isEmpty(x: Int): Boolean = ???
def get: Int = a
def get(x: Int): String = ???
}
diff --git a/tests/pos/i1540b.scala b/tests/pos/i1540b.scala
index 2b4c5408e..f4408b0c7 100644
--- a/tests/pos/i1540b.scala
+++ b/tests/pos/i1540b.scala
@@ -1,6 +1,6 @@
class Casey1[T](val a: T) {
- def isDefined: Boolean = true
- def isDefined(x: T): Boolean = ???
+ def isEmpty: Boolean = false
+ def isEmpty(x: T): Boolean = ???
def get: T = a
def get(x: T): String = ???
}
diff --git a/tests/pos/i1642.scala b/tests/pos/i1642.scala
new file mode 100644
index 000000000..2fe67cf18
--- /dev/null
+++ b/tests/pos/i1642.scala
@@ -0,0 +1,2 @@
+class Test1(val x: Int) extends AnyVal
+class Test2(val y: Test1) extends AnyVal
diff --git a/tests/pos/i1665.scala b/tests/pos/i1665.scala
new file mode 100644
index 000000000..b7e4a4eed
--- /dev/null
+++ b/tests/pos/i1665.scala
@@ -0,0 +1,7 @@
+
+object Test {
+ !=(1)
+ !=("abc")
+ 1 != this
+ !=(this)
+}
diff --git a/tests/pos/i1704.scala b/tests/pos/i1704.scala
new file mode 100644
index 000000000..94bc03c4d
--- /dev/null
+++ b/tests/pos/i1704.scala
@@ -0,0 +1,4 @@
+trait AnyRef {
+ val StringMatch = new AnyRef {}
+ trait Something { (AnyRef) match { case (StringMatch) => } }
+}
diff --git a/tests/pos/i1737.scala b/tests/pos/i1737.scala
new file mode 100644
index 000000000..e7b428717
--- /dev/null
+++ b/tests/pos/i1737.scala
@@ -0,0 +1,11 @@
+object Test {
+ sealed trait Foo[A]
+ case object FooI extends Foo[Int]
+ case class FooS(b: Boolean) extends Foo[String]
+
+ def algFoo[A](foo: Foo[A]): A =
+ foo match {
+ case FooI => 42
+ case FooS(b) => "foo"
+ }
+}
diff --git a/tests/pos/i1751.scala b/tests/pos/i1751.scala
new file mode 100644
index 000000000..d51cdc65d
--- /dev/null
+++ b/tests/pos/i1751.scala
@@ -0,0 +1,17 @@
+trait Break { protected val break: Int; }
+case class BreakImpl(protected val break: Int) extends Break {}
+object Test {
+ def f2(x: Break) = x match {
+ case BreakImpl(x) => BreakImpl
+ case _ => -1
+ }
+ def f4(x: Any) = x match {
+ case BreakImpl(x) => x
+ case _ => -1
+ }
+ def main(args: Array[String]): Unit = {
+ val break = BreakImpl(22)
+ assert(f2(break) == 22)
+ assert(f4(break) == 22)
+ }
+}
diff --git a/tests/pos/i1753.scala b/tests/pos/i1753.scala
new file mode 100644
index 000000000..e5ad743aa
--- /dev/null
+++ b/tests/pos/i1753.scala
@@ -0,0 +1,22 @@
+abstract class BackendInterface {
+ type Symbol >: Null
+ type ClassDef >: Null
+}
+
+class BTypesFromSymbols[I <: BackendInterface](val int: I) {
+ def isRemote(s: int.Symbol) = println("might've been remote")
+}
+
+trait BCodeIdiomatic {
+ val int: BackendInterface
+ final lazy val bTypes = new BTypesFromSymbols[int.type](int)
+}
+
+trait BCodeSkelBuilder extends BCodeIdiomatic {
+ import int._
+ import bTypes._
+ val b: BTypesFromSymbols[int.type] = bTypes
+ val x: int.type = bTypes.int
+ val y: bTypes.int.type = int
+ def getPlainClass(cd: ClassDef) = bTypes.isRemote(null: Symbol)
+}
diff --git a/tests/pos/i1755.scala b/tests/pos/i1755.scala
new file mode 100644
index 000000000..1361ebeec
--- /dev/null
+++ b/tests/pos/i1755.scala
@@ -0,0 +1,21 @@
+class hierarOverload {
+ trait AB {
+ type TB
+ protected trait A { val entities: List[TB] }
+ protected trait B
+ }
+ object NAnB {
+ type TB = nB
+ type TA = nA
+ class nA { List[nB]() }
+ class nB {}
+ }
+ def foo = { val t = new NAnB.TB() }
+}
+class hierarOverload2 {
+ object NAnB {
+ type TB = nB
+ class nB
+ }
+ def foo = { val t = new NAnB.TB() }
+}
diff --git a/tests/pos/i1756.scala b/tests/pos/i1756.scala
new file mode 100644
index 000000000..e6f6eda60
--- /dev/null
+++ b/tests/pos/i1756.scala
@@ -0,0 +1,20 @@
+class A { { val x = this } }
+class B(x: Int) {
+ class C(x: Int)
+ extends B({
+ val test = this
+ x
+ }) {
+ def this() = {
+ this({
+ 1
+ })
+ }
+ }
+}
+
+// Minimized version
+class D(x: Int) {
+ class E(x: Int) extends D({val test = D.this; x})
+}
+
diff --git a/tests/pos/i1757.scala b/tests/pos/i1757.scala
new file mode 100644
index 000000000..515b4e9bb
--- /dev/null
+++ b/tests/pos/i1757.scala
@@ -0,0 +1,6 @@
+case class B[T](b: List[Int]) {
+ var s: B[Int] = ???
+ def cpy[X](b: List[Int] = b): B[X] = new B[X](b)
+ s.cpy()
+ s.copy()
+}
diff --git a/tests/pos/i1765.scala b/tests/pos/i1765.scala
new file mode 100644
index 000000000..d79129638
--- /dev/null
+++ b/tests/pos/i1765.scala
@@ -0,0 +1,21 @@
+trait T[X]
+
+trait U[X]
+
+trait TC[M[_]] {
+ def foo[M[_]: TC, A](ma: U[A]) = ()
+ implicit val TCofT: TC[T] = new TC[T] {}
+ implicit def any2T[A](a: A): T[A] = new T[A] {}
+ implicit def any2U[A](a: A): U[A] = new U[A] {}
+ val x = foo[T, Int](1)
+ val y = ()
+}
+
+// Minimized version exhibiting an assertion violation in Denotation#current at phase lambdalift:
+trait TC2 {
+// implicit val TCofT: TC2[T] = new TC2[T] {}
+ val TCofT: Object = {
+ class C extends TC2
+ new Object
+ }
+}
diff --git a/tests/pos/i1776.scala b/tests/pos/i1776.scala
new file mode 100644
index 000000000..265ded0d8
--- /dev/null
+++ b/tests/pos/i1776.scala
@@ -0,0 +1,3 @@
+class X(val y: String)
+class Y(y: => String) extends X(y)
+class Z(z: => String) extends X(z)
diff --git a/tests/pos/i1777.scala b/tests/pos/i1777.scala
new file mode 100644
index 000000000..381ff9139
--- /dev/null
+++ b/tests/pos/i1777.scala
@@ -0,0 +1,9 @@
+object Main extends App {
+ import scala.collection.immutable._
+ case class Foo(s: String)
+ {
+ implicit val orderingS: Ordering[String] = Ordering[String] // Crash
+ val tree = TreeMap.empty ++ (1 to 100).map { i => Foo(i.toString) -> i }
+ println(tree.getClass)
+ }
+}
diff --git a/tests/pos/i1786.scala b/tests/pos/i1786.scala
new file mode 100644
index 000000000..3b1d3af52
--- /dev/null
+++ b/tests/pos/i1786.scala
@@ -0,0 +1,18 @@
+package scala
+
+package object meta {
+ def apply(x: Int): Int = x * x
+}
+
+class Test {
+ meta { 5 + 4 }
+
+ scala.meta { 3 }
+
+ scala.meta.`package` { 3 }
+
+ // val m1 = meta // error
+ // val m2 = scala.meta // error
+ val m3 = scala.meta.`package`
+ val m4 = meta.`package`
+}
diff --git a/tests/pos/i1790.scala b/tests/pos/i1790.scala
new file mode 100644
index 000000000..7535255f9
--- /dev/null
+++ b/tests/pos/i1790.scala
@@ -0,0 +1,15 @@
+import scala.util.control.NonFatal
+
+class Try[+T] {
+ def transform[U](s: T => Try[U], f: Throwable => Try[U]): Try[U] =
+ try this match {
+ case Success(v) => s(v)
+ case Failure(e) => f(e)
+ } catch {
+ case NonFatal(e) => Failure(e)
+ }
+}
+final case class Success[+T](value: T) extends Try[T]
+final case class Failure[+T](exception: Throwable) extends Try[T] {
+ def get: T = throw exception
+}
diff --git a/tests/pos/i1793.scala b/tests/pos/i1793.scala
new file mode 100644
index 000000000..fed8a6165
--- /dev/null
+++ b/tests/pos/i1793.scala
@@ -0,0 +1,7 @@
+object Test {
+ import scala.ref.WeakReference
+ def unapply[T <: AnyRef](wr: WeakReference[T]): Option[T] = {
+ val x = wr.underlying.get
+ if (x != null) Some(x) else None
+ }
+}
diff --git a/tests/pos/i1795.scala b/tests/pos/i1795.scala
new file mode 100644
index 000000000..3e8bd1e97
--- /dev/null
+++ b/tests/pos/i1795.scala
@@ -0,0 +1,13 @@
+sealed trait T1 {type M1}
+
+case object o1 extends T1
+
+sealed trait T2 {type M2}
+
+case object o2 extends T2
+
+class TestX {
+ type TestT1 <: T1 {type M1 = TestT2}
+ type TestT2 <: T2 {type M2 = TestT1}
+ //val x: TestT1 = o1
+}
diff --git a/tests/pos/i1797.scala b/tests/pos/i1797.scala
new file mode 100644
index 000000000..1f10082b7
--- /dev/null
+++ b/tests/pos/i1797.scala
@@ -0,0 +1 @@
+case class Tuple1[T](_1: T)
diff --git a/tests/pos/i1803.scala b/tests/pos/i1803.scala
new file mode 100644
index 000000000..19bf21918
--- /dev/null
+++ b/tests/pos/i1803.scala
@@ -0,0 +1,7 @@
+class C[T]
+
+object Test {
+ def f(x: C[Int]) = ???
+
+ f(new C {})
+}
diff --git a/tests/pos/i1812.scala b/tests/pos/i1812.scala
new file mode 100644
index 000000000..653274883
--- /dev/null
+++ b/tests/pos/i1812.scala
@@ -0,0 +1,12 @@
+class FF[R] {
+ def compose(): R = ???
+}
+
+class Test(x: Int) extends AnyVal {
+ def method: Unit = {
+ class Bla
+ class Foo extends FF[Bla] {
+ override def compose() = super[FF].compose()
+ }
+ }
+}
diff --git a/tests/pos/i1812b.scala b/tests/pos/i1812b.scala
new file mode 100644
index 000000000..492c545f1
--- /dev/null
+++ b/tests/pos/i1812b.scala
@@ -0,0 +1,11 @@
+class FF[R] {
+ def compose(): R = ???
+}
+
+class Test(x: Int) extends AnyVal {
+ def method: Unit = {
+ class Bla{ def bar:a.S = ???}
+ trait TRT{ type S}
+ val a: TRT = ???
+ }
+}
diff --git a/tests/pos/i1865.scala b/tests/pos/i1865.scala
new file mode 100644
index 000000000..1b77558ff
--- /dev/null
+++ b/tests/pos/i1865.scala
@@ -0,0 +1,24 @@
+class AbsCell {
+ type T = Node
+ class Node
+}
+
+object Test {
+ def test: Unit = {
+ val cell = new AbsCell
+ new cell.T
+ }
+}
+
+class AbsCell2 {
+ type T = Node
+ val value: T = value
+ def set(x: T): Unit = {}
+ class Node
+}
+object init {
+ def main = {
+ val cell = new AbsCell2 { val init = new Node }
+ cell set (new cell.T)
+ }
+}
diff --git a/tests/pos/i1867.scala b/tests/pos/i1867.scala
new file mode 100644
index 000000000..b6377c4f0
--- /dev/null
+++ b/tests/pos/i1867.scala
@@ -0,0 +1,3 @@
+trait B {
+ def f1: {}
+}
diff --git a/tests/pos/i1868.scala b/tests/pos/i1868.scala
new file mode 100644
index 000000000..3ca3e0094
--- /dev/null
+++ b/tests/pos/i1868.scala
@@ -0,0 +1,7 @@
+class Test[X](x: X) {
+ def checkSpecialization[Y](y: Y): X = {
+ def specMe[@specialized T]() = ()
+ x
+ }
+ private def checkNameStartsWith(prefix: String) = { (new Exception) }
+}
diff --git a/tests/pos/i1891.scala b/tests/pos/i1891.scala
new file mode 100644
index 000000000..b178c256b
--- /dev/null
+++ b/tests/pos/i1891.scala
@@ -0,0 +1,11 @@
+object Test {
+ class CC2[A, B](a: A, b: B)
+
+ type T2[A, B] = CC2[A, B]
+
+ class ArrowAssoc[A](val self: A) {
+ @inline def f[B](y: B): CC2[A, B] = new CC2(self, y)
+ }
+
+ def foo = (new ArrowAssoc(1)).f(2)
+}
diff --git a/tests/pos/implicits.scala b/tests/pos/implicits.scala
index 1a3e0b4da..feb48771f 100644
--- a/tests/pos/implicits.scala
+++ b/tests/pos/implicits.scala
@@ -6,4 +6,9 @@ object Test {
val x: X = Byte.MinValue
+ def foo() = {
+ implicit val x = "abc"
+ implicitly[String]
+ }
+
}
diff --git a/tests/pos/lazyValsSepComp.scala b/tests/pos/lazyValsSepComp.scala
index 1a7e37020..048231eb0 100644
--- a/tests/pos/lazyValsSepComp.scala
+++ b/tests/pos/lazyValsSepComp.scala
@@ -12,5 +12,5 @@ import dotty.tools.dotc.core.Contexts._
object Foo {
val definitions: Definitions = null
def defn = definitions
- def go = defn.FunctionType(0)
+ def go = defn.FunctionClassPerRun
}
diff --git a/tests/pos/pos_valueclasses/optmatch.scala b/tests/pos/pos_valueclasses/optmatch.scala
index a7995a455..ff1a17906 100644
--- a/tests/pos/pos_valueclasses/optmatch.scala
+++ b/tests/pos/pos_valueclasses/optmatch.scala
@@ -7,7 +7,7 @@ package optmatch
class NonZeroLong(val value: Long) extends AnyVal {
def get: Long = value
- def isDefined: Boolean = get != 0l
+ def isEmpty: Boolean = get == 0l
}
object NonZeroLong {
def unapply(value: Long): NonZeroLong = new NonZeroLong(value)