aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/valueClasses.scala2
-rw-r--r--tests/pos/valueclasses/privatethisparam.scala18
-rw-r--r--tests/run/patmat-option-named.scala21
3 files changed, 39 insertions, 2 deletions
diff --git a/tests/neg/valueClasses.scala b/tests/neg/valueClasses.scala
index ae90ef63c..74a576ce6 100644
--- a/tests/neg/valueClasses.scala
+++ b/tests/neg/valueClasses.scala
@@ -6,5 +6,3 @@ class B1 {
class B2(x: Int) extends AnyVal // error: value class may not be a local class
}
}
-class C(private[this] val u: Int) extends AnyVal // error: value class parameter must not be private[this]
-class D(u: Int) extends AnyVal // error: value class parameter must not be private[this]
diff --git a/tests/pos/valueclasses/privatethisparam.scala b/tests/pos/valueclasses/privatethisparam.scala
new file mode 100644
index 000000000..77ca9851c
--- /dev/null
+++ b/tests/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/run/patmat-option-named.scala b/tests/run/patmat-option-named.scala
new file mode 100644
index 000000000..b27d07107
--- /dev/null
+++ b/tests/run/patmat-option-named.scala
@@ -0,0 +1,21 @@
+case class HasSingleField(f: HasSingleField)
+
+object Test {
+
+ def main(args: Array[String]) = {
+ val s: Object = HasSingleField(null)
+ s match {
+ case Matcher(self) =>
+ assert(self ne null)
+ }
+ }
+}
+
+object Matcher {
+ def unapply(x: Object): Option[HasSingleField] = {
+ if (x.isInstanceOf[HasSingleField])
+ Some(x.asInstanceOf[HasSingleField])
+ else
+ None
+ }
+}