From e5b02a88e66af0d5e9c37a881ac0237bf1d38387 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 6 Apr 2015 18:32:38 +0200 Subject: Enable pending 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. The remaining tests with "extends AnyVal" in tests/pending/pos are related to separate compilation, except for: - t6482.scala and t7022.scala which were fixed by https://github.com/scala/scala/pull/1468 in scalac and seem to trigger a similar bug in FullParameterization - strip-tvars-for-lubbasetypes.scala which was fixed by https://github.com/scala/scala/pull/1758 in scalac --- tests/pos/valueclasses/optmatch.scala | 35 +++++++++++++++++++++++++++++++++++ tests/pos/valueclasses/t5667.scala | 6 ++++++ tests/pos/valueclasses/t5953.scala | 18 ++++++++++++++++++ tests/pos/valueclasses/t6260a.scala | 17 +++++++++++++++++ tests/pos/valueclasses/t8011.scala | 10 ++++++++++ 5 files changed, 86 insertions(+) create mode 100644 tests/pos/valueclasses/optmatch.scala create mode 100644 tests/pos/valueclasses/t5667.scala create mode 100644 tests/pos/valueclasses/t5953.scala create mode 100644 tests/pos/valueclasses/t6260a.scala create mode 100644 tests/pos/valueclasses/t8011.scala (limited to 'tests/pos/valueclasses') diff --git a/tests/pos/valueclasses/optmatch.scala b/tests/pos/valueclasses/optmatch.scala new file mode 100644 index 000000000..a7995a455 --- /dev/null +++ b/tests/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/valueclasses/t5667.scala b/tests/pos/valueclasses/t5667.scala new file mode 100644 index 000000000..80efb181b --- /dev/null +++ b/tests/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/valueclasses/t5953.scala b/tests/pos/valueclasses/t5953.scala new file mode 100644 index 000000000..669fac7df --- /dev/null +++ b/tests/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/valueclasses/t6260a.scala b/tests/pos/valueclasses/t6260a.scala new file mode 100644 index 000000000..e29f10452 --- /dev/null +++ b/tests/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/valueclasses/t8011.scala b/tests/pos/valueclasses/t8011.scala new file mode 100644 index 000000000..88b4b53aa --- /dev/null +++ b/tests/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 } -- cgit v1.2.3