Skip to content

Commit 070c9d7

Browse files
committed
Fix #4922: unapplySeq mustn't allow arrays
1 parent d3b3192 commit 070c9d7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ object Applications {
101101

102102
if (unapplyName == nme.unapplySeq) {
103103
if (unapplyResult derivesFrom defn.SeqClass) seqSelector :: Nil
104-
else if (isGetMatch(unapplyResult, pos)) {
104+
else if (isGetMatch(unapplyResult, pos) && getTp.derivesFrom(defn.SeqClass)) {
105105
val seqArg = getTp.elemType.hiBound
106106
if (seqArg.exists) args.map(Function.const(seqArg))
107107
else fail

tests/neg/i4922.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class SQ {
2+
val isEmpty = false
3+
val get = Array(1)
4+
}
5+
object A {
6+
def unapplySeq(a: Int): SQ = new SQ
7+
}
8+
9+
object Main {
10+
def main(args: Array[String]): Unit = {
11+
val seq: Seq[Int] = 2 match {
12+
case A(xs: _*) => xs // error // error
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)