Skip to content

Commit 17e8921

Browse files
authored
Merge pull request #4928 from dotty-staging/fix-4922-unapplySeq-arrays
Fix #4922: unapplySeq mustn't allow arrays
2 parents 3bf8a16 + 070c9d7 commit 17e8921

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
@@ -102,7 +102,7 @@ object Applications {
102102

103103
if (unapplyName == nme.unapplySeq) {
104104
if (unapplyResult derivesFrom defn.SeqClass) seqSelector :: Nil
105-
else if (isGetMatch(unapplyResult, pos)) {
105+
else if (isGetMatch(unapplyResult, pos) && getTp.derivesFrom(defn.SeqClass)) {
106106
val seqArg = getTp.elemType.hiBound
107107
if (seqArg.exists) args.map(Function.const(seqArg))
108108
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)