aboutsummaryrefslogtreecommitdiff
path: root/tests/pos
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2015-04-04 01:15:30 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-05-01 13:27:42 +0200
commit06e1905aed315d5199936797c9e9493326b74595 (patch)
treedb50094702d250935ecbafd465542d4c11adc5d5 /tests/pos
parent411d5be477cc862b14d8938c591524d8bf37d4cd (diff)
downloaddotty-06e1905aed315d5199936797c9e9493326b74595.tar.gz
dotty-06e1905aed315d5199936797c9e9493326b74595.tar.bz2
dotty-06e1905aed315d5199936797c9e9493326b74595.zip
Enable untried pos tests related to value classes
Each test needs to have its own package because pos_all will try to compile the whole valueclasses directory at once.
Diffstat (limited to 'tests/pos')
-rw-r--r--tests/pos/valueclasses/nullAsInstanceOfVC.scala2
-rw-r--r--tests/pos/valueclasses/t5853.scala57
-rw-r--r--tests/pos/valueclasses/t6029.scala5
-rw-r--r--tests/pos/valueclasses/t6034.scala3
-rw-r--r--tests/pos/valueclasses/t6215.scala3
-rw-r--r--tests/pos/valueclasses/t6260.scala19
-rw-r--r--tests/pos/valueclasses/t6260b.scala5
-rw-r--r--tests/pos/valueclasses/t6358.scala8
-rw-r--r--tests/pos/valueclasses/t6358_2.scala8
-rw-r--r--tests/pos/valueclasses/t6601/PrivateValueClass_1.scala3
-rw-r--r--tests/pos/valueclasses/t6601/UsePrivateValueClass_2.scala12
-rw-r--r--tests/pos/valueclasses/t6651.scala35
-rw-r--r--tests/pos/valueclasses/t7818.scala12
-rw-r--r--tests/pos/valueclasses/value-class-override-no-spec.flags1
-rw-r--r--tests/pos/valueclasses/value-class-override-no-spec.scala11
-rw-r--r--tests/pos/valueclasses/value-class-override-spec.scala11
-rw-r--r--tests/pos/valueclasses/xlint1.flags1
-rw-r--r--tests/pos/valueclasses/xlint1.scala15
18 files changed, 211 insertions, 0 deletions
diff --git a/tests/pos/valueclasses/nullAsInstanceOfVC.scala b/tests/pos/valueclasses/nullAsInstanceOfVC.scala
index 0c1232883..43af839ec 100644
--- a/tests/pos/valueclasses/nullAsInstanceOfVC.scala
+++ b/tests/pos/valueclasses/nullAsInstanceOfVC.scala
@@ -1,3 +1,5 @@
+package nullAsInstanceOfVC
+
// These issues were originally reported in SI-5866 and SI-8097
// FIXME: Make this a run test once we have run tests.
diff --git a/tests/pos/valueclasses/t5853.scala b/tests/pos/valueclasses/t5853.scala
new file mode 100644
index 000000000..82ac9dd1d
--- /dev/null
+++ b/tests/pos/valueclasses/t5853.scala
@@ -0,0 +1,57 @@
+package t5853
+
+
+
+
+
+
+
+
+final class C(val x: Int) extends AnyVal {
+ def ppp[@specialized(Int) T](y: T) = ()
+}
+
+
+class Foo {
+ def f = new C(1) ppp 2
+}
+
+
+/* Original SI-5853 test-case. */
+
+object Bippy {
+ implicit final class C(val x: Int) extends AnyVal {
+ def +++[@specialized T](y: T) = ()
+ }
+ def f = 1 +++ 2
+}
+
+
+/* Few more examples. */
+
+final class C2(val x: Int) extends AnyVal {
+ def +++[@specialized(Int) T](y: T) = ()
+}
+
+
+class Foo2 {
+ def f = new C2(1) +++ 2
+}
+
+
+object Arrow {
+ implicit final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal {
+ @inline def ->>[B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y)
+ }
+
+ def foo = 1 ->> 2
+}
+
+
+object SpecArrow {
+ implicit final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal {
+ @inline def ->> [@specialized(Int) B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y)
+ }
+
+ def foo = 1 ->> 2
+}
diff --git a/tests/pos/valueclasses/t6029.scala b/tests/pos/valueclasses/t6029.scala
new file mode 100644
index 000000000..13f8f8830
--- /dev/null
+++ b/tests/pos/valueclasses/t6029.scala
@@ -0,0 +1,5 @@
+package t6029
+
+final case class V[A](x: A) extends AnyVal {
+ def flatMap[B](f: A => V[B]) = if (true) this else f(x)
+}
diff --git a/tests/pos/valueclasses/t6034.scala b/tests/pos/valueclasses/t6034.scala
new file mode 100644
index 000000000..8e2fb625c
--- /dev/null
+++ b/tests/pos/valueclasses/t6034.scala
@@ -0,0 +1,3 @@
+package t6034
+
+final class OptPlus[+A](val x: A) extends AnyVal { }
diff --git a/tests/pos/valueclasses/t6215.scala b/tests/pos/valueclasses/t6215.scala
new file mode 100644
index 000000000..579503e6c
--- /dev/null
+++ b/tests/pos/valueclasses/t6215.scala
@@ -0,0 +1,3 @@
+package t6215
+
+class Foo(val v: String) extends AnyVal { private def len = v.length ; def f = len }
diff --git a/tests/pos/valueclasses/t6260.scala b/tests/pos/valueclasses/t6260.scala
new file mode 100644
index 000000000..675c3c16a
--- /dev/null
+++ b/tests/pos/valueclasses/t6260.scala
@@ -0,0 +1,19 @@
+package t6260
+
+class Box[X](val x: X) extends AnyVal {
+ def map[Y](f: X => Y): Box[Y] =
+ ((bx: Box[X]) => new Box(f(bx.x)))(this)
+}
+
+object Test {
+ def map2[X, Y](self: Box[X], f: X => Y): Box[Y] =
+ ((bx: Box[X]) => new Box(f(bx.x)))(self)
+
+ def main(args: Array[String]): Unit = {
+ val f = (x: Int) => x + 1
+ val g = (x: String) => x + x
+
+ map2(new Box(42), f)
+ new Box("abc") map g
+ }
+}
diff --git a/tests/pos/valueclasses/t6260b.scala b/tests/pos/valueclasses/t6260b.scala
new file mode 100644
index 000000000..fb9a2961b
--- /dev/null
+++ b/tests/pos/valueclasses/t6260b.scala
@@ -0,0 +1,5 @@
+package t6260b
+
+
+class X(val value: Object) extends AnyVal { def or(alt: => X): X = this }
+class Y { def f = new X("") or new X("") }
diff --git a/tests/pos/valueclasses/t6358.scala b/tests/pos/valueclasses/t6358.scala
new file mode 100644
index 000000000..291ae2e9e
--- /dev/null
+++ b/tests/pos/valueclasses/t6358.scala
@@ -0,0 +1,8 @@
+package t6358
+
+class L(val t: Int) extends AnyVal {
+ def lazyString = {
+ lazy val x = t.toString
+ () => x
+ }
+}
diff --git a/tests/pos/valueclasses/t6358_2.scala b/tests/pos/valueclasses/t6358_2.scala
new file mode 100644
index 000000000..effac505a
--- /dev/null
+++ b/tests/pos/valueclasses/t6358_2.scala
@@ -0,0 +1,8 @@
+package t6358_2
+
+class Y[T](val i: Option[T]) extends AnyVal {
+ def q: List[T] = {
+ lazy val e: List[T] = i.toList
+ e
+ }
+}
diff --git a/tests/pos/valueclasses/t6601/PrivateValueClass_1.scala b/tests/pos/valueclasses/t6601/PrivateValueClass_1.scala
new file mode 100644
index 000000000..fc6f3e422
--- /dev/null
+++ b/tests/pos/valueclasses/t6601/PrivateValueClass_1.scala
@@ -0,0 +1,3 @@
+package t6601
+
+class V private (val a: Any) extends AnyVal
diff --git a/tests/pos/valueclasses/t6601/UsePrivateValueClass_2.scala b/tests/pos/valueclasses/t6601/UsePrivateValueClass_2.scala
new file mode 100644
index 000000000..acd0dbef9
--- /dev/null
+++ b/tests/pos/valueclasses/t6601/UsePrivateValueClass_2.scala
@@ -0,0 +1,12 @@
+package t6601
+
+object Test {
+ // After the first attempt to make seprately compiled value
+ // classes respect the privacy of constructors, we got:
+ //
+ // exception when typing v.a().==(v.a())/class scala.reflect.internal.Trees$Apply
+ // constructor V in class V cannot be accessed in object Test in file test/files/pos/t6601/UsePrivateValueClass_2.scala
+ // scala.reflect.internal.Types$TypeError: constructor V in class V cannot be accessed in object Test
+ def foo(v: V) = v.a == v.a
+ def bar(v: V) = v == v
+}
diff --git a/tests/pos/valueclasses/t6651.scala b/tests/pos/valueclasses/t6651.scala
new file mode 100644
index 000000000..6201b6de3
--- /dev/null
+++ b/tests/pos/valueclasses/t6651.scala
@@ -0,0 +1,35 @@
+package t6651
+
+class YouAreYourself[A <: AnyRef](val you: A) extends AnyVal {
+ def yourself: you.type = you
+}
+
+object Test {
+ val s = ""
+ val s1: s.type = new YouAreYourself[s.type](s).yourself
+}
+
+trait Path {
+ type Dep <: AnyRef
+}
+
+final class ValueClass[P <: Path](val path: P) extends AnyVal {
+ import path.Dep
+
+ def apply(dep: Dep)(d2: dep.type, foo: Int): (Dep, d2.type) = (d2, d2)
+
+ // This generates dodgy code; note `ValueClass.this`:
+ //
+ // final def bounds$extension[D >: Nothing <: ValueClass.this.path.Dep,
+ // P >: Nothing <: Path]
+ // ($this: ValueClass[P])
+ // (dep: D)
+ // (d2: dep.type, foo: Int): (D, d2.type) = scala.Tuple2.apply[D, d2.type](d2, d2);
+ //
+ // Nothing crashes down the line, but it certainly doesn't conform to best-practices.
+ //
+ // An better alternative would be to add a type parameter for the (singleton) type of
+ // the wrapped value.
+ def bounds[D <: Dep](dep: D)(d2: dep.type, foo: Int): (D, d2.type) = (d2, d2)
+}
+
diff --git a/tests/pos/valueclasses/t7818.scala b/tests/pos/valueclasses/t7818.scala
new file mode 100644
index 000000000..31f542366
--- /dev/null
+++ b/tests/pos/valueclasses/t7818.scala
@@ -0,0 +1,12 @@
+package t7818
+
+class Observable1[+T](val asJava: JObservable[_ <: T]) extends AnyVal {
+ private def foo[X](a: JObservable[X]): JObservable[X] = ???
+ // was generating a type error as the type of the RHS included an existential
+ // skolem based on the class type parameter `T`, which did not conform
+ // to the typer parameter of the extension method into which the RHS is
+ // transplanted.
+ def synchronize: Observable1[T] = new Observable1(foo(asJava))
+}
+
+class JObservable[T]
diff --git a/tests/pos/valueclasses/value-class-override-no-spec.flags b/tests/pos/valueclasses/value-class-override-no-spec.flags
new file mode 100644
index 000000000..a7e64e4f0
--- /dev/null
+++ b/tests/pos/valueclasses/value-class-override-no-spec.flags
@@ -0,0 +1 @@
+-no-specialization \ No newline at end of file
diff --git a/tests/pos/valueclasses/value-class-override-no-spec.scala b/tests/pos/valueclasses/value-class-override-no-spec.scala
new file mode 100644
index 000000000..058e3e911
--- /dev/null
+++ b/tests/pos/valueclasses/value-class-override-no-spec.scala
@@ -0,0 +1,11 @@
+package value_class_override_no_spec
+
+// There are two versions of this tests: one with and one without specialization.
+// The bug was only exposed *without* specialization.
+trait T extends Any {
+ def x: Any
+}
+
+final class StringOps(val repr0: String) extends AnyVal with T {
+ def x = ()
+}
diff --git a/tests/pos/valueclasses/value-class-override-spec.scala b/tests/pos/valueclasses/value-class-override-spec.scala
new file mode 100644
index 000000000..c315be8d0
--- /dev/null
+++ b/tests/pos/valueclasses/value-class-override-spec.scala
@@ -0,0 +1,11 @@
+package value_class_override_spec
+
+// There are two versions of this tests: one with and one without specialization.
+// The bug was only exposed *without* specialization.
+trait T extends Any {
+ def x: Any
+}
+
+final class StringOps(val repr0: String) extends AnyVal with T {
+ def x = ()
+}
diff --git a/tests/pos/valueclasses/xlint1.flags b/tests/pos/valueclasses/xlint1.flags
new file mode 100644
index 000000000..7949c2afa
--- /dev/null
+++ b/tests/pos/valueclasses/xlint1.flags
@@ -0,0 +1 @@
+-Xlint -Xfatal-warnings
diff --git a/tests/pos/valueclasses/xlint1.scala b/tests/pos/valueclasses/xlint1.scala
new file mode 100644
index 000000000..c2f39f9b3
--- /dev/null
+++ b/tests/pos/valueclasses/xlint1.scala
@@ -0,0 +1,15 @@
+package xlint1
+
+package object foo {
+ implicit class Bar[T](val x: T) extends AnyVal {
+ def bippy = 1
+ }
+}
+
+package foo {
+ object Baz {
+ def main(args: Array[String]): Unit = {
+ "abc".bippy
+ }
+ }
+}