Skip to content

Commit 117aacd

Browse files
committed
Adapt test to support irrefutable unapplySeq
Now if the result type of an unapplySeq conforms to a sequence match, it will be taken as an irrefutable sequence match --- `isEmpty` and `get` defined on the type are ignored. Thus, we need to rewrite the test.
1 parent 551774b commit 117aacd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tests/run/string-extractor.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
final class StringExtract(val s: String) extends AnyVal {
2-
def isEmpty = (s eq null) || (s == "")
3-
def get = this
42
def length = s.length
53
def lengthCompare(n: Int) = s.length compare n
64
def apply(idx: Int): Char = s charAt idx
@@ -13,7 +11,6 @@ final class StringExtract(val s: String) extends AnyVal {
1311
}
1412

1513
final class ThreeStringExtract(val s: String) extends AnyVal {
16-
def isEmpty = (s eq null) || (s == "")
1714
def get: (List[Int], Double, Seq[Char]) = ((s.length :: Nil, s.length.toDouble, toSeq))
1815
def length = s.length
1916
def lengthCompare(n: Int) = s.length compare n
@@ -28,10 +25,14 @@ final class ThreeStringExtract(val s: String) extends AnyVal {
2825

2926

3027
object Bippy {
31-
def unapplySeq(x: Any): StringExtract = new StringExtract("" + x)
28+
def unapplySeq(x: Any): Option[StringExtract] =
29+
if ((x == null) || (x == "")) None
30+
else Some(new StringExtract("" + x))
3231
}
3332
object TripleBippy {
34-
def unapplySeq(x: Any): ThreeStringExtract = new ThreeStringExtract("" + x)
33+
def unapplySeq(x: Any): Option[(List[Int], Double, Seq[Char])] =
34+
if ((x == null) || (x == "")) then None
35+
else Some(new ThreeStringExtract("" + x).get)
3536
}
3637

3738
object Test {

0 commit comments

Comments
 (0)