diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-10-06 11:40:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-06 11:40:30 +0200 |
commit | a3064622e7ce4d73ddd91de0fc6bebfe0ec23ae9 (patch) | |
tree | 9085c715a63a324088c28ddc25828315d7cb1358 /tests/pos/pos_valueclasses | |
parent | 93d4c8c945540d5df7ee9e8541abcf112439bb1e (diff) | |
parent | 46b325373c8ec516be2b6b1c6024ae1c783fbc8f (diff) | |
download | dotty-a3064622e7ce4d73ddd91de0fc6bebfe0ec23ae9.tar.gz dotty-a3064622e7ce4d73ddd91de0fc6bebfe0ec23ae9.tar.bz2 dotty-a3064622e7ce4d73ddd91de0fc6bebfe0ec23ae9.zip |
Merge pull request #1494 from martijnhoekstra/wintests
[WIP] fix encoding issues
Diffstat (limited to 'tests/pos/pos_valueclasses')
28 files changed, 398 insertions, 0 deletions
diff --git a/tests/pos/pos_valueclasses/nullAsInstanceOfVC.scala b/tests/pos/pos_valueclasses/nullAsInstanceOfVC.scala new file mode 100644 index 000000000..43af839ec --- /dev/null +++ b/tests/pos/pos_valueclasses/nullAsInstanceOfVC.scala @@ -0,0 +1,29 @@ +package nullAsInstanceOfVC + +// These issues were originally reported in SI-5866 and SI-8097 +// FIXME: Make this a run test once we have run tests. + +object VCNull { + case class Foo(d: Double) extends AnyVal { + override def toString = s"Foo($d)" + } + case class Bar(s: String) extends AnyVal { + override def toString = s"Bar($s)" + } + + def testDirect(): Unit = { + val fooDirect: Foo = null.asInstanceOf[Foo] + val barDirect: Bar = null.asInstanceOf[Bar] + } + + def testIndirect(): Unit = { + val fooIndirect: Foo = { val n: Any = null; n.asInstanceOf[Foo] } + val barIndirect: Bar = { val n: Any = null; n.asInstanceOf[Bar] } + } + + def nullOf[T]: T = null.asInstanceOf[T] + def testGeneric(): Unit = { + val fooGeneric: Foo = nullOf[Foo] + val barGeneric: Bar = nullOf[Bar] + } +} diff --git a/tests/pos/pos_valueclasses/optmatch.scala b/tests/pos/pos_valueclasses/optmatch.scala new file mode 100644 index 000000000..a7995a455 --- /dev/null +++ b/tests/pos/pos_valueclasses/optmatch.scala @@ -0,0 +1,35 @@ +package optmatch + +// final case class NonZeroLong(value: Long) extends AnyVal { +// def get: Long = value +// def isEmpty: Boolean = get == 0l +// } + +class NonZeroLong(val value: Long) extends AnyVal { + def get: Long = value + def isDefined: Boolean = get != 0l +} +object NonZeroLong { + def unapply(value: Long): NonZeroLong = new NonZeroLong(value) +} + + +object Foo { + def unapply(x: Int): NonZeroLong = new NonZeroLong(1L << x) + // public long unapply(int); + // 0: lconst_1 + // 1: iload_1 + // 2: lshl + // 3: lreturn +} + +object Test { + def f(x: Int): Int = x match { + case Foo(1024l) => 1 + case _ => 2 + } + def main(args: Array[String]): Unit = { + println(f(10)) + println(f(11)) + } +} diff --git a/tests/pos/pos_valueclasses/paramlists.scala b/tests/pos/pos_valueclasses/paramlists.scala new file mode 100644 index 000000000..f390a44e0 --- /dev/null +++ b/tests/pos/pos_valueclasses/paramlists.scala @@ -0,0 +1,37 @@ +package paramlists + +class Meter[T](val x: T) extends AnyVal { + def zero: T = x + def zero2[M >: T]: M = x + def one(): T = x + def one2[M >: T](): M = x + def one3(x: T): T = x + def one4[M >: T](x: M): M = x + def two(x: T)(y: T): T = y + def two2[M >: T](x: T)(y: M): M = y +} + +object Test { + def test: Unit = { + val m1 = new Meter(1) + m1.zero + m1.zero2 + m1.one + m1.one2 + m1.one3(10) + m1.two(11)(12) + m1.two2(11)(12) + + { + import m1._ + + zero + zero2 + one + one2 + one3(10) + two(11)(12) + two2(11)(12) + } + } +} diff --git a/tests/pos/pos_valueclasses/privatethisparam.scala b/tests/pos/pos_valueclasses/privatethisparam.scala new file mode 100644 index 000000000..77ca9851c --- /dev/null +++ b/tests/pos/pos_valueclasses/privatethisparam.scala @@ -0,0 +1,18 @@ +package privatethisparam + +class Meter[T](x: T) extends AnyVal { + def zero: T = x +} + +class Meter2(private[this] val x: Int) extends AnyVal { + def foo = x +} + +object Test { + def bar = new Meter2(42) + def useZero = new Meter(5).zero + def test: Unit = { + val m1 = new Meter(1) + m1.zero + } +}
\ No newline at end of file diff --git a/tests/pos/pos_valueclasses/t5667.scala b/tests/pos/pos_valueclasses/t5667.scala new file mode 100644 index 000000000..80efb181b --- /dev/null +++ b/tests/pos/pos_valueclasses/t5667.scala @@ -0,0 +1,6 @@ +package t5667 + +object Main { + implicit class C(val s: String) extends AnyVal + implicit class C2(val s: String) extends AnyRef +} diff --git a/tests/pos/pos_valueclasses/t5853.scala b/tests/pos/pos_valueclasses/t5853.scala new file mode 100644 index 000000000..82ac9dd1d --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t5953.scala b/tests/pos/pos_valueclasses/t5953.scala new file mode 100644 index 000000000..669fac7df --- /dev/null +++ b/tests/pos/pos_valueclasses/t5953.scala @@ -0,0 +1,18 @@ +package t5953 + +import scala.collection.{ mutable, immutable, generic, GenTraversableOnce } + +package object foo { + @inline implicit class TravOps[A, CC[A] <: GenTraversableOnce[A]](val coll: CC[A]) extends AnyVal { + def build[CC2[X]](implicit cbf: generic.CanBuildFrom[Nothing, A, CC2[A]]): CC2[A] = { + cbf() ++= coll.toIterator result + } + } +} + +package foo { + object Test { + def f1[T](xs: Traversable[T]) = xs.to[immutable.Vector] + def f2[T](xs: Traversable[T]) = xs.build[immutable.Vector] + } +} diff --git a/tests/pos/pos_valueclasses/t6029.scala b/tests/pos/pos_valueclasses/t6029.scala new file mode 100644 index 000000000..13f8f8830 --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t6034.scala b/tests/pos/pos_valueclasses/t6034.scala new file mode 100644 index 000000000..8e2fb625c --- /dev/null +++ b/tests/pos/pos_valueclasses/t6034.scala @@ -0,0 +1,3 @@ +package t6034 + +final class OptPlus[+A](val x: A) extends AnyVal { } diff --git a/tests/pos/pos_valueclasses/t6215.scala b/tests/pos/pos_valueclasses/t6215.scala new file mode 100644 index 000000000..579503e6c --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t6260.scala b/tests/pos/pos_valueclasses/t6260.scala new file mode 100644 index 000000000..675c3c16a --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t6260a.scala b/tests/pos/pos_valueclasses/t6260a.scala new file mode 100644 index 000000000..e29f10452 --- /dev/null +++ b/tests/pos/pos_valueclasses/t6260a.scala @@ -0,0 +1,17 @@ +package t6260a + +final class Option[+A](val value: A) extends AnyVal + +// Was: sandbox/test.scala:21: error: bridge generated for member method f: ()Option[A] in class Bar +// which overrides method f: ()Option[A] in class Foo" +abstract class Foo[A] { def f(): Option[A] } + class Bar[A] extends Foo[A] { def f(): Option[A] = ??? } + +// User reported this as erroneous but I couldn't reproduce with 2.10.{0,1,2,3} +// https://issues.scala-lang.org/browse/SI-6260?focusedCommentId=64764&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-64764 +// I suspect he whittled down the example too far. +class Wrapper(val value: Int) extends AnyVal +abstract class Test { def check(the: Wrapper): Boolean } +object T { + new Test { def check(the: Wrapper) = true } +} diff --git a/tests/pos/pos_valueclasses/t6260b.scala b/tests/pos/pos_valueclasses/t6260b.scala new file mode 100644 index 000000000..fb9a2961b --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t6358.scala b/tests/pos/pos_valueclasses/t6358.scala new file mode 100644 index 000000000..291ae2e9e --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t6358_2.scala b/tests/pos/pos_valueclasses/t6358_2.scala new file mode 100644 index 000000000..effac505a --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t6601/PrivateValueClass_1.scala b/tests/pos/pos_valueclasses/t6601/PrivateValueClass_1.scala new file mode 100644 index 000000000..fc6f3e422 --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t6601/UsePrivateValueClass_2.scala b/tests/pos/pos_valueclasses/t6601/UsePrivateValueClass_2.scala new file mode 100644 index 000000000..acd0dbef9 --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t6651.scala b/tests/pos/pos_valueclasses/t6651.scala new file mode 100644 index 000000000..6201b6de3 --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t7818.scala b/tests/pos/pos_valueclasses/t7818.scala new file mode 100644 index 000000000..31f542366 --- /dev/null +++ b/tests/pos/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/pos_valueclasses/t8011.scala b/tests/pos/pos_valueclasses/t8011.scala new file mode 100644 index 000000000..88b4b53aa --- /dev/null +++ b/tests/pos/pos_valueclasses/t8011.scala @@ -0,0 +1,10 @@ +package t8011 + +class ThingOps1(val x: String) extends AnyVal { + def fn[A]: Any = { + new X[A] { def foo(a: A) = a } + 0 + } +} + +trait X[B] { def foo(a: B): Any } diff --git a/tests/pos/pos_valueclasses/t9298/JUse.java b/tests/pos/pos_valueclasses/t9298/JUse.java new file mode 100644 index 000000000..a872c895a --- /dev/null +++ b/tests/pos/pos_valueclasses/t9298/JUse.java @@ -0,0 +1,7 @@ +package t9298; + +class JUse { + public static Meter jm() { + return new Meter(2); + } +} diff --git a/tests/pos/pos_valueclasses/t9298/Meter.scala b/tests/pos/pos_valueclasses/t9298/Meter.scala new file mode 100644 index 000000000..290b28509 --- /dev/null +++ b/tests/pos/pos_valueclasses/t9298/Meter.scala @@ -0,0 +1,3 @@ +package t9298 + +class Meter(val x: Int) extends AnyVal diff --git a/tests/pos/pos_valueclasses/t9298/Use.scala b/tests/pos/pos_valueclasses/t9298/Use.scala new file mode 100644 index 000000000..41f1fb035 --- /dev/null +++ b/tests/pos/pos_valueclasses/t9298/Use.scala @@ -0,0 +1,9 @@ +// TODO: this should be a run test once we have run tests + +package t9298 + +object Use { + def main(args: Array[String]): Unit = { + val x: Meter = JUse.jm + } +} diff --git a/tests/pos/pos_valueclasses/value-class-override-no-spec.flags b/tests/pos/pos_valueclasses/value-class-override-no-spec.flags new file mode 100644 index 000000000..a7e64e4f0 --- /dev/null +++ b/tests/pos/pos_valueclasses/value-class-override-no-spec.flags @@ -0,0 +1 @@ +-no-specialization
\ No newline at end of file diff --git a/tests/pos/pos_valueclasses/value-class-override-no-spec.scala b/tests/pos/pos_valueclasses/value-class-override-no-spec.scala new file mode 100644 index 000000000..058e3e911 --- /dev/null +++ b/tests/pos/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/pos_valueclasses/value-class-override-spec.scala b/tests/pos/pos_valueclasses/value-class-override-spec.scala new file mode 100644 index 000000000..c315be8d0 --- /dev/null +++ b/tests/pos/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/pos_valueclasses/xlint1.flags b/tests/pos/pos_valueclasses/xlint1.flags new file mode 100644 index 000000000..7949c2afa --- /dev/null +++ b/tests/pos/pos_valueclasses/xlint1.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/tests/pos/pos_valueclasses/xlint1.scala b/tests/pos/pos_valueclasses/xlint1.scala new file mode 100644 index 000000000..c2f39f9b3 --- /dev/null +++ b/tests/pos/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 + } + } +} |