-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fails to parse XML literal as NodeBuffer #8214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Somehow, the println on the last line is seen by the parser as part of the expression started on the previous line: ./bin/dotc -Xprint:parser -classpath "$(coursier fetch -p org.scala-lang.modules:scala-xml_2.13:2.0.0-M1)" try/i8214.scala
parsed:
package <empty> {
import scala.xml.NodeBuffer
module object Test {
val nodeBuffer: NodeBuffer =
{
val $buf = new _root_.scala.xml.NodeBuffer()
$buf.&+(
{
{
new _root_.scala.xml.Elem(null, "hello", _root_.scala.xml.Null,
$scope
, true)
}
}
)
$buf.&+(
{
{
new _root_.scala.xml.Elem(null, "world", _root_.scala.xml.Null,
$scope
, true)
}
}
)
$buf
} println ()
}
}
-- [E008] Member Not Found Error: try/i8214.scala:4:2 --------------------------
3 | val nodeBuffer: NodeBuffer = <hello/><world/>
4 | println()
| ^
| value println is not a member of scala.xml.NodeBuffer
1 error found |
Since I am strongly in favor of abandoning XML literals for Scala 3 I won't put effort in fixing this. It seems like a non-obvious interaction between the XML parser (which I don't know) and the normal parser. Somebody else should take this on if there's interest in fixing this. |
As a workaround, one can add braces around the xml expression: import scala.xml.NodeBuffer
object Test {
val nodeBuffer: NodeBuffer = {
<hello/><world/>
}
println()
} |
This is a duplicate of scala/bug#9027. I'll attempt a PR that reapplies the patch. That old PR was on 2.11, had a backport to 2.10, and now will have a forward port to 3. |
Forward port of scala/scala#4185
Fix #8214 Don't consume whitespace after XML
Forward port of scala/scala#4185
In 2.13.1, it was possible to specify multiple XML literal elements and have them parsed as
NodeBuffer
(usually parsing one would be anElem
). I don't think this capability is used very often in Scala code bases, but given how much Scala code is out there, it is worth surfacing this regression.It works fine in a REPL (dotty doesn't have
:paste
?), but not in a file:Here's an example repo with a branch with this defect:
https://github.com/ashawley/dotty-scala-xml-example/tree/nodebuffer
The text was updated successfully, but these errors were encountered: