Skip to content

Commit 5d1f0b4

Browse files
committed
tryfix(16459): workaround LARROW, but find a corner-case
Confusing LARROW just after XML pattern breaks the parser.
1 parent 0423862 commit 5d1f0b4

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

tests/run/i16459.scala

+40-11
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@ object Test {
22
import scala.xml.*
33
def main(args: Array[String]): Unit = {
44

5-
val singleQuotedTextCase = if(true) {
5+
val xml = if(true) {
66
<script type="text/javascript">
77
'location.reload()'
88
'foo bar'
99
</script>
1010
} else <div>empty</div>
11-
12-
val casePatMatch = for (case t @ <foo>FooBar</foo> <- Seq(xml))
13-
yield t
14-
// TODO: This fails
15-
val casePatMatchWithCond = for (case t @ <foo>FooBar</foo> if true <- Seq(xml))
16-
yield t
1711

1812
assert(
1913
xml match
@@ -26,7 +20,45 @@ object Test {
2620
,
2721
xml
2822
)
23+
// Scala 3 syntax
24+
val auxiliary0 = if true then {
25+
<script type="text/javascript">
26+
'location.reload()'
27+
'foo bar'
28+
</script>
29+
} else <div>empty</div>
30+
31+
val auxiliary1 = if true then
32+
<script type="text/javascript">
33+
'location.reload()'
34+
'foo bar'
35+
</script>
36+
else <div>empty</div>
37+
38+
val auxiliary2 = if true then <div>A</div>else <div>B</div>
39+
40+
// Note:
41+
// This does not pass in Scala 2.12.18 and 2.13.12
42+
// due to "Sequence argument type annotation `: _*` cannot be used here:"
43+
val auxiliary3 = if(true) <div>A</div>else <div>B</div>
44+
45+
// Note: This passes in Scala 2.12.18 and 2.13.12 too.
46+
val auxiliary4 = if(true) <div attr="...">A</div>else <div attr="...">B</div>
47+
48+
// Pattern match without guard.
49+
// Note: This passes in Scala 2.12.18 and 2.13.12 too.
50+
val auxiliary5 = for (case _ @ <div>empty</div> <- Seq(xml)) yield ()
51+
val auxiliary6 = for (case _ @ <div>empty</div><- Seq(xml)) yield ()
52+
val auxiliary7 = for (case _ @ <div>empty</div><-Seq(xml)) yield ()
53+
// Pattern match with if guard.
54+
// Note: This passes in Scala 2.12.18 and 2.13.12 too.
55+
val auxiliary8 = for (case _ @ <foo>FooBar</foo> <- Seq(xml) if true)
56+
val auxiliary9 = for (case _ @ <foo>FooBar</foo><- Seq(xml) if true)
57+
val auxiliary10 = for (case _ @ <foo>FooBar</foo><-Seq(xml) if true)
58+
yield ()
59+
2960
}
61+
3062
}
3163

3264
package scala.xml {
@@ -46,10 +78,7 @@ package scala.xml {
4678
def child: Seq[Node]
4779
override def toString = label + child.mkString
4880
}
49-
class Comment(commentText: String) extends Node{
50-
def label = commentText
51-
def child = Nil
52-
}
81+
5382
class Elem(prefix: String, val label: String, attributes1: MetaData, scope: NamespaceBinding, minimizeEmpty: Boolean, val child: Node*) extends Node
5483
object Elem {
5584
def unapply(e:Elem):Option[(String,String,Any,Text,Any)] = Some(("dummy","dummy",null,null,null))

0 commit comments

Comments
 (0)