From e826be8e2bd5e13788a4261cecba82fd86da862c Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Fri, 16 Jul 2021 18:28:13 -0400 Subject: [PATCH] fix #541 by working around Scala 3 compiler bug --- .../scala/xml/parsing/ConstructingParserTest.scala | 14 +++++++++++++- .../scala/scala/xml/parsing/MarkupParser.scala | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/jvm/src/test/scala/scala/xml/parsing/ConstructingParserTest.scala b/jvm/src/test/scala/scala/xml/parsing/ConstructingParserTest.scala index 413cd9a74..fb8590d00 100644 --- a/jvm/src/test/scala/scala/xml/parsing/ConstructingParserTest.scala +++ b/jvm/src/test/scala/scala/xml/parsing/ConstructingParserTest.scala @@ -75,10 +75,22 @@ class ConstructingParserTest { @Test def SI6341issue65: Unit = { val str = """""" - val cpa = ConstructingParser.fromSource(io.Source.fromString(str), preserveWS = true) + val cpa = ConstructingParser.fromSource(Source.fromString(str), preserveWS = true) val cpadoc = cpa.document() val ppr = new PrettyPrinter(80,5) val out = ppr.format(cpadoc.docElem) assertEquals(str, out) } + + // https://github.com/scala/scala-xml/issues/541 + @Test + def issue541: Unit = { + val xml = + """|""".stripMargin + val parser = ConstructingParser.fromSource(Source.fromString(xml), preserveWS = true) + parser.document().docElem // shouldn't crash + } + } diff --git a/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala b/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala index 95ec2ec55..acd19485e 100755 --- a/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala +++ b/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala @@ -58,7 +58,10 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { protected var curInput: Source = input // See ticket #3720 for motivations. - private class WithLookAhead(underlying: Source) extends Source { + // As for why it's `private[parsing]` rather than merely `private`, see + // https://github.com/scala/scala-xml/issues/541 ; the broader access is necessary, + // for now anyway, to work around https://github.com/lampepfl/dotty/issues/13096 + private[parsing] class WithLookAhead(underlying: Source) extends Source { private val queue = scala.collection.mutable.Queue[Char]() def lookahead(): BufferedIterator[Char] = { val iter = queue.iterator ++ new Iterator[Char] {