Skip to content

Commit 169afc8

Browse files
committed
Add more tests
1 parent 703a3b3 commit 169afc8

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
424424
List()
425425
else {
426426
val isUnapplySeq = unappSym.name == nme.unapplySeq
427-
if (isProductMatch(mt.finalResultType, argLen) && !isUnapplySeq) {
427+
if (productArity(mt.finalResultType, unappSym.sourcePos) > 0 && !isUnapplySeq) {
428428
productSelectors(mt.finalResultType).take(argLen)
429429
.map(_.info.asSeenFrom(mt.finalResultType, mt.resultType.classSymbol).widenExpr)
430430
}

tests/neg/i3248.scala

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/run/i3248b.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
object Test {
2+
class Foo(val name: String, val children: Int *)
3+
object Foo {
4+
def unapply(f: Foo) = Some((f.name, f.children))
5+
}
6+
7+
def foo(f: Foo) = f match {
8+
case Foo(name, ns: _*) =>
9+
assert(name == "hello")
10+
assert(ns(0) == 3)
11+
assert(ns(1) == 5)
12+
}
13+
14+
def bar(f: Foo) = f match {
15+
case Foo(name, x, y, ns : _*) =>
16+
assert(name == "hello")
17+
assert(x == 3)
18+
assert(y == 5)
19+
assert(ns.isEmpty)
20+
}
21+
22+
def main(args: Array[String]): Unit = {
23+
val f = new Foo("hello", 3, 5)
24+
foo(f)
25+
bar(f)
26+
}
27+
}

tests/run/i3248c.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
object Test {
2+
case class Foo(name: String, children: Int *)
3+
4+
def foo(f: Foo) = f match {
5+
case Foo(name, ns: _*) =>
6+
assert(name == "hello")
7+
assert(ns(0) == 3)
8+
assert(ns(1) == 5)
9+
}
10+
11+
def bar(f: Foo) = f match {
12+
case Foo(name, x, y, ns : _*) =>
13+
assert(name == "hello")
14+
assert(x == 3)
15+
assert(y == 5)
16+
assert(ns.isEmpty)
17+
}
18+
19+
def main(args: Array[String]): Unit = {
20+
val f = new Foo("hello", 3, 5)
21+
foo(f)
22+
bar(f)
23+
}
24+
}

0 commit comments

Comments
 (0)