Skip to content

Commit 606e36b

Browse files
oderskyfelixmulder
authored andcommitted
Fix #1976: Hack to support scala.xml's $scope (#1977)
This is a gross hack to support the need for a $scope binding when XML literals are created. It should go away once we phase out XML literals. A library-based solution should use implicits instead.
1 parent 38a385a commit 606e36b

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ class Definitions {
527527
lazy val EqType = ctx.requiredClassRef("scala.Eq")
528528
def EqClass(implicit ctx: Context) = EqType.symbol.asClass
529529

530+
lazy val XMLTopScopeModuleRef = ctx.requiredModuleRef("scala.xml.TopScope")
531+
530532
// Annotation base classes
531533
lazy val AnnotationType = ctx.requiredClassRef("scala.annotation.Annotation")
532534
def AnnotationClass(implicit ctx: Context) = AnnotationType.symbol.asClass

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ object StdNames {
533533
val nullRuntimeClass: N = "scala.runtime.Null$"
534534

535535
val synthSwitch: N = "$synthSwitch"
536+
val _scope: N = "$scope"
536537

537538
// unencoded operators
538539
object raw {

compiler/src/dotty/tools/dotc/parsing/SymbolicXMLBuilder.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
5555
val _buf: TermName = "$buf"
5656
val _md: TermName = "$md"
5757
val _plus: TermName = "$amp$plus"
58-
val _scope: TermName = "$scope"
5958
val _tmpscope: TermName = "$tmpscope"
6059
val _xml: TermName = "xml"
6160
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
351351
val ownType =
352352
if (rawType.exists)
353353
ensureAccessible(rawType, superAccess = false, tree.pos)
354+
else if (name == nme._scope) {
355+
// gross hack to support current xml literals.
356+
// awaiting a better implicits based solution for library-supported xml
357+
return ref(defn.XMLTopScopeModuleRef)
358+
}
354359
else
355360
errorType(new MissingIdent(tree, kind, name.show), tree.pos)
356361

tests/pos/i1976.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
import scala.xml._
3+
val node = <node>{ "whatever " }</node>
4+
}

0 commit comments

Comments
 (0)