Skip to content

Commit 8ed4016

Browse files
Add migration warning for XML literals in language future (#19101)
First step towards #19100
2 parents eb4962b + 45a48db commit 8ed4016

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

compiler/src/dotty/tools/dotc/config/MigrationVersion.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ object MigrationVersion:
3838
val ImportWildcard = MigrationVersion(future, future)
3939
val ImportRename = MigrationVersion(future, future)
4040
val ParameterEnclosedByParenthesis = MigrationVersion(future, future)
41+
val XmlLiteral = MigrationVersion(future, future)
4142

4243
end MigrationVersion

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,16 @@ object Parsers {
571571

572572
object symbXMLBuilder extends xml.SymbolicXMLBuilder(this, true) // DEBUG choices
573573

574-
def xmlLiteral() : Tree = xmlp.xLiteral
575-
def xmlLiteralPattern() : Tree = xmlp.xLiteralPattern
574+
def xmlLiteral() : Tree = xmlDeprecationWarning(xmlp.xLiteral)
575+
def xmlLiteralPattern() : Tree = xmlDeprecationWarning(xmlp.xLiteralPattern)
576+
577+
private def xmlDeprecationWarning(tree: Tree): Tree =
578+
report.errorOrMigrationWarning(
579+
em"""XML literals are no longer supported.
580+
|See https://docs.scala-lang.org/scala3/reference/dropped-features/xml.html""",
581+
tree.srcPos,
582+
MigrationVersion.XmlLiteral)
583+
tree
576584

577585
/* -------- COMBINATORS -------------------------------------------------------- */
578586

compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ object MarkupParsers {
277277
* | xmlTag1 '/' '>'
278278
*/
279279
def element: Tree = {
280-
val start = curOffset
280+
val start = curOffset // FIXME should be `curOffset - 1` (scalatest and tests/neg/i19100.scala must be updated)
281281
val (qname, attrMap) = xTag(())
282282
if (ch == '/') { // empty element
283283
xToken("/>")
@@ -435,7 +435,7 @@ object MarkupParsers {
435435
* | Name [S] '/' '>'
436436
*/
437437
def xPattern: Tree = {
438-
var start = curOffset
438+
var start = curOffset // FIXME should be `curOffset - 1` (scalatest and tests/neg/i19100.scala must be updated)
439439
val qname = xName
440440
debugLastStartElement = (start, qname) :: debugLastStartElement
441441
xSpaceOpt()

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import parsing.{Parser => ParserPhase}
1212
import config.Printers.typr
1313
import inlines.PrepareInlineable
1414
import util.Stats.*
15+
import dotty.tools.dotc.config.Feature
16+
import dotty.tools.dotc.config.SourceVersion
1517

1618
/**
1719
*
@@ -83,7 +85,7 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase {
8385

8486
ctx.base.parserPhase match {
8587
case p: ParserPhase =>
86-
if p.firstXmlPos.exists && !defn.ScalaXmlPackageClass.exists then
88+
if p.firstXmlPos.exists && !defn.ScalaXmlPackageClass.exists && Feature.sourceVersion == SourceVersion.future then
8789
report.error(
8890
"""To support XML literals, your project must depend on scala-xml.
8991
|See https://github.com/scala/scala-xml for more information.""".stripMargin,

tests/neg/i19100.check

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Error: tests/neg/i19100.scala:4:3 -----------------------------------------------------------------------------------
2+
4 | <foo/> match // error
3+
| ^^^^^
4+
| XML literals are no longer supported.
5+
| See https://docs.scala-lang.org/scala3/reference/dropped-features/xml.html
6+
-- Error: tests/neg/i19100.scala:5:10 ----------------------------------------------------------------------------------
7+
5 | case <foo/> => 1 // error
8+
| ^^^^^
9+
| XML literals are no longer supported.
10+
| See https://docs.scala-lang.org/scala3/reference/dropped-features/xml.html
11+
-- Error: tests/neg/i19100.scala:6:3 -----------------------------------------------------------------------------------
12+
6 | <bar></bar> // error
13+
| ^^^^^^^^^^
14+
| XML literals are no longer supported.
15+
| See https://docs.scala-lang.org/scala3/reference/dropped-features/xml.html

tests/neg/i19100.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.language.future
2+
3+
def test =
4+
<foo/> match // error
5+
case <foo/> => 1 // error
6+
<bar></bar> // error

0 commit comments

Comments
 (0)