Skip to content

Commit 495fdb3

Browse files
committed
Merge pull request scala#4123 from retronym/ticket/8253
SI-8253 Fix incorrect parsing of <elem xmlns={f("a")}/>
2 parents 1810ac0 + 8d175b9 commit 495fdb3

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ abstract class SymbolicXMLBuilder(p: Parsers#Parser, preserveWS: Boolean) {
184184
)
185185

186186
val uri1 = attrMap(z) match {
187-
case Apply(_, List(uri @ Literal(Constant(_)))) => mkAssign(uri)
187+
case Apply(Select(New(Select(Select(Select(Ident(nme.ROOTPKG), nme.scala_), nme.xml), tpnme.Text)), nme.CONSTRUCTOR), List(uri @ Literal(Constant(_)))) =>
188+
mkAssign(uri)
188189
case Select(_, nme.Nil) => mkAssign(const(null)) // allow for xmlns="" -- bug #1626
189190
case x => mkAssign(x)
190191
}

src/reflect/scala/reflect/internal/StdNames.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ trait StdNames {
248248
final val Unliftable: NameType = "Unliftable"
249249
final val Name: NameType = "Name"
250250
final val Tree: NameType = "Tree"
251+
final val Text: NameType = "Text"
251252
final val TermName: NameType = "TermName"
252253
final val Type : NameType = "Type"
253254
final val TypeName: NameType = "TypeName"
@@ -778,6 +779,7 @@ trait StdNames {
778779
val values : NameType = "values"
779780
val wait_ : NameType = "wait"
780781
val withFilter: NameType = "withFilter"
782+
val xml: NameType = "xml"
781783
val zero: NameType = "zero"
782784

783785
// quasiquote interpolators:

test/files/run/t8253.check

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
<sample xmlns='ns1'/>
3+
{
4+
var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
5+
$tmpscope = new _root_.scala.xml.NamespaceBinding(null, "ns1", $tmpscope);
6+
{
7+
val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
8+
new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
9+
}
10+
}
11+
12+
<sample xmlns={identity(ns1)}/>
13+
{
14+
var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
15+
$tmpscope = new _root_.scala.xml.NamespaceBinding(null, ns1, $tmpscope);
16+
{
17+
val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
18+
new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
19+
}
20+
}
21+
22+
<sample xmlns:foo='ns1'/>
23+
{
24+
var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
25+
$tmpscope = new _root_.scala.xml.NamespaceBinding("foo", "ns1", $tmpscope);
26+
{
27+
val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
28+
new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
29+
}
30+
}
31+
32+
<sample xmlns:foo={identity(ns1)}/>
33+
{
34+
var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
35+
$tmpscope = new _root_.scala.xml.NamespaceBinding("foo", ns1, $tmpscope);
36+
{
37+
val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
38+
new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
39+
}
40+
}

test/files/run/t8253.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Test extends App {
2+
import reflect.runtime.universe._ // not using the XML library in compiler tests
3+
4+
def show(code: String, t: Tree) = println(s"\n$code\n$t")
5+
6+
val ns1 = "ns1"
7+
show("<sample xmlns='ns1'/>", q"<sample xmlns='ns1'/>")
8+
show("<sample xmlns={identity(ns1)}/>", q"<sample xmlns={ns1}/>")
9+
show("<sample xmlns:foo='ns1'/>", q"<sample xmlns:foo='ns1'/>")
10+
show("<sample xmlns:foo={identity(ns1)}/>", q"<sample xmlns:foo={ns1}/>")
11+
12+
// `identity(foo)` used to match the overly permissive match in SymbolXMLBuilder
13+
// which was intented to more specifically match `_root_.scala.xml.Text(...)`
14+
}

0 commit comments

Comments
 (0)