diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
index 18294a28b4a1..41e9eeabe370 100644
--- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -906,6 +906,7 @@ object Parsers {
var braces = 0
while (true) {
val token = lookahead.token
+ if (query != LARROW && token == XMLSTART) return false
if (braces == 0) {
if (token == query) return true
if (stopScanTokens.contains(token) || lookahead.isNestedEnd) return false
@@ -927,6 +928,7 @@ object Parsers {
lookahead.nextToken()
while (parens != 0 && lookahead.token != EOF) {
val token = lookahead.token
+ if (token == XMLSTART) return true
if (token == LPAREN) parens += 1
else if (token == RPAREN) parens -= 1
lookahead.nextToken()
diff --git a/tests/run/i16459.scala b/tests/run/i16459.scala
new file mode 100644
index 000000000000..2964928d522c
--- /dev/null
+++ b/tests/run/i16459.scala
@@ -0,0 +1,107 @@
+object Test {
+ import scala.xml.*
+ def main(args: Array[String]): Unit = {
+
+ val xml = if(true) {
+
+ } else
empty
+
+ assert(
+ xml match
+ case elm: Elem if
+ elm.label == "script"
+ && elm.child.length == 1
+ && elm.child(0) == Atom(Text("\n 'location.reload()'\n 'foo bar'\n "))
+ => true
+ case _ => false
+ ,
+ xml
+ )
+ // Scala 3 syntax
+ val auxiliary0 = if true then {
+
+ } else empty
+
+ val auxiliary1 = if true then
+
+ else empty
+
+ val auxiliary2 = if true then A
else B
+
+ // Note:
+ // This does not pass in Scala 2.12.18 and 2.13.12
+ // due to "Sequence argument type annotation `: _*` cannot be used here:"
+ val auxiliary3 = if(true) A
else B
+
+ // Note: This passes in Scala 2.12.18 and 2.13.12 too.
+ val auxiliary4 = if(true) A
else B
+
+ // Pattern match without guard.
+ // Note: This passes in Scala 2.12.18 and 2.13.12 too.
+ val auxiliary5 = for (case _ @ empty
<- Seq(xml)) yield ()
+ // Note: These pass in Scala 2.12.18 and 2.13.12.
+ val auxiliary6 = for (case _ @ empty
<- Seq(xml)) yield ()
+ val auxiliary7 = for (case _ @ empty
<-Seq(xml)) yield ()
+ // Pattern match with if guard.
+ // Note: This passes in Scala 2.12.18 and 2.13.12 too.
+ val auxiliary8 = for (case _ @ FooBar <- Seq(xml) if true)
+ yield ()
+ // Note: These pass in Scala 2.12.18 and 2.13.12.
+ val auxiliary9 = for (case _ @ FooBar<- Seq(xml) if true)
+ yield ()
+ val auxiliary10 = for (case _ @ FooBar<-Seq(xml) if true)
+ yield ()
+
+ }
+
+}
+
+package scala.xml {
+ type MetaData = AnyRef
+
+ class UnprefixedAttribute(
+ val key: String,
+ val value: Text,
+ next1: MetaData
+ ) extends MetaData
+
+ trait NamespaceBinding
+ object TopScope extends NamespaceBinding
+ object Null
+ abstract class Node {
+ def label: String
+ def child: Seq[Node]
+ override def toString = label + child.mkString
+ }
+
+ class Elem(prefix: String, val label: String, attributes1: MetaData, scope: NamespaceBinding, minimizeEmpty: Boolean, val child: Node*) extends Node
+ object Elem {
+ def unapply(e:Elem):Option[(String,String,Any,Text,Any)] = Some(("dummy","dummy",null,null,null))
+ }
+ class NodeBuffer extends Seq[Node] {
+ val nodes = scala.collection.mutable.ArrayBuffer.empty[Node]
+ def &+(o: Any): NodeBuffer = o match {
+ case n: Node => nodes.addOne(n) ; this
+ case t: Text => nodes.addOne(Atom(t)) ; this
+ }
+ // Members declared in scala.collection.IterableOnce
+ def iterator: Iterator[scala.xml.Node] = nodes.iterator
+ // Members declared in scala.collection.SeqOps
+ def apply(i: Int): scala.xml.Node = nodes(i)
+ def length: Int = nodes.length
+ }
+ case class Text(text: String)
+ case class Atom(t: Text) extends Node {
+ def label = t.text
+ def child = Nil
+ }
+}
\ No newline at end of file