Skip to content

Commit 8b51f43

Browse files
committed
Bug in unapplySeq from scala-xml
Compiler error was found in scala-xml on 2.13.0-M5: 18: error: error during expansion of this match (this is a scalac bug) The underlying error was: type mismatch; found : Seq[Node] (in scala.collection) required: Seq[Node] (in scala.collection.immutable) def f(n: Node) = n match { This was Lukas Rytz's minimal example that could reproduce: abstract class Node extends NodeSeq { def label: String def child: scala.collection.Seq[Node] } object Elem { def unapplySeq(n: Node): Option[(String, collection.Seq[Node])] = Some((n.label, n.child)) } abstract class NodeSeq extends collection.Seq[Node] { def iterator: Iterator[Node] = ??? def apply(i: Int): Node = ??? def length: Int = ??? } object Test { def f(n: Node) = n match { case Elem(label, child @ _*) => child } }
1 parent c8fe7c8 commit 8b51f43

File tree

3 files changed

+247
-0
lines changed

3 files changed

+247
-0
lines changed

test/files/neg/t11102.check

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
t11102.scala:5: error: error during expansion of this match (this is a scalac bug).
2+
The underlying error was: type mismatch;
3+
found : Seq[MutableCons] (in scala.collection.mutable)
4+
required: Seq[MutableCons] (in scala.collection.immutable)
5+
def f(x: MutableSeq) = x match {
6+
^
7+
t11102.scala:8: error: error during expansion of this match (this is a scalac bug).
8+
The underlying error was: type mismatch;
9+
found : Seq[CollectionCons] (in scala.collection)
10+
required: Seq[CollectionCons] (in scala.collection.immutable)
11+
def f(x: CollectionSeq) = x match {
12+
^
13+
two errors found

test/files/neg/t11102.scala

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
object Test {
2+
def f(x: ImmutableSeq) = x match {
3+
case ImmutableCons(x, xs @ _*) => xs
4+
}
5+
def f(x: MutableSeq) = x match {
6+
case MutableCons(x, xs @ _*) => xs
7+
}
8+
def f(x: CollectionSeq) = x match {
9+
case CollectionCons(x, xs @ _*) => xs
10+
}
11+
def f(x: ScalaSeq) = x match {
12+
case ScalaCons(x, xs @ _*) => xs
13+
}
14+
def f(x: DefaultSeq) = x match {
15+
case DefaultCons(x, xs @ _*) => xs
16+
}
17+
}
18+
19+
/**
20+
* collection.immutable.Seq
21+
*/
22+
abstract class ImmutableSeq
23+
extends collection.immutable.Seq[Int]
24+
with UnimplementedSeq
25+
26+
object ImmutableCons {
27+
def unapplySeq(x: ImmutableCons) =
28+
Some((x.first, x.more))
29+
}
30+
31+
abstract class ImmutableCons
32+
extends ImmutableSeq {
33+
def first: Int
34+
def more: collection.immutable.Seq[ImmutableCons]
35+
}
36+
37+
/**
38+
* collection.mutable.Seq
39+
*/
40+
abstract class MutableSeq
41+
extends collection.mutable.Seq[Int]
42+
with UnimplementedSeq
43+
44+
object MutableCons {
45+
def unapplySeq(x: MutableCons) =
46+
Some((x.first, x.more)) // !
47+
}
48+
49+
abstract class MutableCons
50+
extends MutableSeq {
51+
def first: Int
52+
def more: collection.mutable.Seq[MutableCons]
53+
}
54+
55+
/**
56+
* collection.Seq
57+
*/
58+
abstract class CollectionSeq
59+
extends collection.Seq[Int]
60+
with UnimplementedSeq
61+
62+
object CollectionCons {
63+
def unapplySeq(x: CollectionCons) =
64+
Some((x.first, x.more)) // !
65+
}
66+
67+
abstract class CollectionCons
68+
extends CollectionSeq {
69+
def first: Int
70+
def more: collection.Seq[CollectionCons]
71+
}
72+
73+
/**
74+
* scala.Seq
75+
*/
76+
abstract class ScalaSeq
77+
extends collection.Seq[Int]
78+
with UnimplementedSeq
79+
80+
object ScalaCons {
81+
def unapplySeq(x: ScalaCons) =
82+
Some((x.first, x.more))
83+
}
84+
85+
abstract class ScalaCons
86+
extends ScalaSeq {
87+
def first: Int
88+
def more: scala.Seq[ScalaCons]
89+
}
90+
91+
/**
92+
* Seq
93+
*/
94+
abstract class DefaultSeq
95+
extends Seq[Int]
96+
with UnimplementedSeq
97+
98+
object DefaultCons {
99+
def unapplySeq(x: DefaultCons) =
100+
Some((x.first, x.more))
101+
}
102+
103+
abstract class DefaultCons
104+
extends DefaultSeq {
105+
def first: Int
106+
def more: Seq[DefaultCons]
107+
}
108+
109+
/**
110+
* Unimplemented sequence.
111+
*/
112+
trait UnimplementedSeq {
113+
def iterator: Iterator[Int] = ???
114+
def apply(i: Int): Int = ???
115+
def length: Int = ???
116+
def update(idx: Int, elem: Int): Unit = ???
117+
}

test/files/pos/t11102.scala

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
object Test {
2+
def f(x: ImmutableSeq) = x match {
3+
case ImmutableCons(x, xs @ _*) => xs
4+
}
5+
def f(x: MutableSeq) = x match {
6+
case MutableCons(x, xs @ _*) => xs
7+
}
8+
def f(x: CollectionSeq) = x match {
9+
case CollectionCons(x, xs @ _*) => xs
10+
}
11+
def f(x: ScalaSeq) = x match {
12+
case ScalaCons(x, xs @ _*) => xs
13+
}
14+
def f(x: DefaultSeq) = x match {
15+
case DefaultCons(x, xs @ _*) => xs
16+
}
17+
}
18+
19+
/**
20+
* collection.immutable.Seq
21+
*/
22+
abstract class ImmutableSeq
23+
extends collection.immutable.Seq[Int]
24+
with UnimplementedSeq
25+
26+
object ImmutableCons {
27+
def unapplySeq(x: ImmutableCons) =
28+
Some((x.first, x.more))
29+
}
30+
31+
abstract class ImmutableCons
32+
extends ImmutableSeq {
33+
def first: Int
34+
def more: collection.immutable.Seq[ImmutableCons]
35+
}
36+
37+
/**
38+
* collection.mutable.Seq
39+
*/
40+
abstract class MutableSeq
41+
extends collection.mutable.Seq[Int]
42+
with UnimplementedSeq
43+
44+
object MutableCons {
45+
def unapplySeq(x: MutableCons) =
46+
Some((x.first, x.more.toSeq)) // !
47+
}
48+
49+
abstract class MutableCons
50+
extends MutableSeq {
51+
def first: Int
52+
def more: collection.mutable.Seq[MutableCons]
53+
}
54+
55+
/**
56+
* collection.Seq
57+
*/
58+
abstract class CollectionSeq
59+
extends collection.Seq[Int]
60+
with UnimplementedSeq
61+
62+
object CollectionCons {
63+
def unapplySeq(x: CollectionCons) =
64+
Some((x.first, x.more.toSeq)) // !
65+
}
66+
67+
abstract class CollectionCons
68+
extends CollectionSeq {
69+
def first: Int
70+
def more: collection.Seq[CollectionCons]
71+
}
72+
73+
/**
74+
* scala.Seq
75+
*/
76+
abstract class ScalaSeq
77+
extends collection.Seq[Int]
78+
with UnimplementedSeq
79+
80+
object ScalaCons {
81+
def unapplySeq(x: ScalaCons) =
82+
Some((x.first, x.more))
83+
}
84+
85+
abstract class ScalaCons
86+
extends ScalaSeq {
87+
def first: Int
88+
def more: scala.Seq[ScalaCons]
89+
}
90+
91+
/**
92+
* Seq
93+
*/
94+
abstract class DefaultSeq
95+
extends Seq[Int]
96+
with UnimplementedSeq
97+
98+
object DefaultCons {
99+
def unapplySeq(x: DefaultCons) =
100+
Some((x.first, x.more))
101+
}
102+
103+
abstract class DefaultCons
104+
extends DefaultSeq {
105+
def first: Int
106+
def more: Seq[DefaultCons]
107+
}
108+
109+
/**
110+
* Unimplemented sequence.
111+
*/
112+
trait UnimplementedSeq {
113+
def iterator: Iterator[Int] = ???
114+
def apply(i: Int): Int = ???
115+
def length: Int = ???
116+
def update(idx: Int, elem: Int): Unit = ???
117+
}

0 commit comments

Comments
 (0)