@@ -11,6 +11,7 @@ import parsing.Parsers.Parser
1111import config .Config
1212import config .Printers .{typr , default }
1313import util .Stats ._
14+ import util .{ SourcePosition , NoSourcePosition }
1415import scala .util .control .NonFatal
1516import ast .Trees ._
1617
@@ -25,6 +26,11 @@ class FrontEnd extends Phase {
2526 /** The contexts for compilation units that are parsed but not yet entered */
2627 private [this ] var remaining : List [Context ] = Nil
2728
29+ /** The position of the first XML literal encountered while parsing,
30+ * NoSourcePosition if there were no XML literals.
31+ */
32+ private [this ] var firstXmlPos : SourcePosition = NoSourcePosition
33+
2834 /** Does a source file ending with `<name>.scala` belong to a compilation unit
2935 * that is parsed but not yet entered?
3036 */
@@ -41,9 +47,17 @@ class FrontEnd extends Phase {
4147
4248 def parse (implicit ctx : Context ): Unit = monitor(" parsing" ) {
4349 val unit = ctx.compilationUnit
50+
4451 unit.untpdTree =
4552 if (unit.isJava) new JavaParser (unit.source).parse()
46- else new Parser (unit.source).parse()
53+ else {
54+ val p = new Parser (unit.source)
55+ val tree = p.parse()
56+ if (p.firstXmlPos.exists && ! firstXmlPos.exists)
57+ firstXmlPos = p.firstXmlPos
58+ tree
59+ }
60+
4761 val printer = if (ctx.settings.Xprint .value.contains(" parser" )) default else typr
4862 printer.println(" parsed:\n " + unit.untpdTree.show)
4963 if (Config .checkPositions)
@@ -86,6 +100,12 @@ class FrontEnd extends Phase {
86100 enterSyms(remaining.head)
87101 remaining = remaining.tail
88102 }
103+
104+ if (firstXmlPos.exists && ! defn.ScalaXmlPackageClass .exists)
105+ ctx.error(""" To support XML literals, your project must depend on scala-xml.
106+ |See https://github.com/scala/scala-xml for more information.""" .stripMargin,
107+ firstXmlPos)
108+
89109 unitContexts.foreach(typeCheck(_))
90110 record(" total trees after typer" , ast.Trees .ntrees)
91111 unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper)
0 commit comments