Skip to content

Commit

Permalink
Add migration warning for XML literals in language future
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 29, 2023
1 parent c88c0fe commit dd105da
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ object MigrationVersion:
val ImportWildcard = MigrationVersion(future, future)
val ImportRename = MigrationVersion(future, future)
val ParameterEnclosedByParenthesis = MigrationVersion(future, future)
val XmlLiteral = MigrationVersion(future, future)

end MigrationVersion
12 changes: 10 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,16 @@ object Parsers {

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

def xmlLiteral() : Tree = xmlp.xLiteral
def xmlLiteralPattern() : Tree = xmlp.xLiteralPattern
def xmlLiteral() : Tree = xmlDeprecationWarning(xmlp.xLiteral)
def xmlLiteralPattern() : Tree = xmlDeprecationWarning(xmlp.xLiteralPattern)

private def xmlDeprecationWarning(tree: Tree): Tree =
report.errorOrMigrationWarning(
em"""XML literals are no longer supported.
|See https://docs.scala-lang.org/scala3/reference/dropped-features/xml.html""",
tree.srcPos,
MigrationVersion.XmlLiteral)
tree

/* -------- COMBINATORS -------------------------------------------------------- */

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ object MarkupParsers {
* | xmlTag1 '/' '>'
*/
def element: Tree = {
val start = curOffset
val start = curOffset - 1
val (qname, attrMap) = xTag(())
if (ch == '/') { // empty element
xToken("/>")
Expand Down Expand Up @@ -435,7 +435,7 @@ object MarkupParsers {
* | Name [S] '/' '>'
*/
def xPattern: Tree = {
var start = curOffset
var start = curOffset - 1
val qname = xName
debugLastStartElement = (start, qname) :: debugLastStartElement
xSpaceOpt()
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/TyperPhase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import parsing.{Parser => ParserPhase}
import config.Printers.typr
import inlines.PrepareInlineable
import util.Stats.*
import dotty.tools.dotc.config.Feature
import dotty.tools.dotc.config.SourceVersion

/**
*
Expand Down Expand Up @@ -83,7 +85,7 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase {

ctx.base.parserPhase match {
case p: ParserPhase =>
if p.firstXmlPos.exists && !defn.ScalaXmlPackageClass.exists then
if p.firstXmlPos.exists && !defn.ScalaXmlPackageClass.exists && Feature.sourceVersion == SourceVersion.future then
report.error(
"""To support XML literals, your project must depend on scala-xml.
|See https://github.com/scala/scala-xml for more information.""".stripMargin,
Expand Down
15 changes: 15 additions & 0 deletions tests/neg/i19100.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Error: tests/neg/i19100.scala:4:2 -----------------------------------------------------------------------------------
4 | <foo/> match // error
| ^^^^^^
| XML literals are no longer supported.
| See https://docs.scala-lang.org/scala3/reference/dropped-features/xml.html
-- Error: tests/neg/i19100.scala:5:9 -----------------------------------------------------------------------------------
5 | case <foo/> => 1 // error
| ^^^^^^
| XML literals are no longer supported.
| See https://docs.scala-lang.org/scala3/reference/dropped-features/xml.html
-- Error: tests/neg/i19100.scala:6:2 -----------------------------------------------------------------------------------
6 | <bar></bar> // error
| ^^^^^^^^^^^
| XML literals are no longer supported.
| See https://docs.scala-lang.org/scala3/reference/dropped-features/xml.html
6 changes: 6 additions & 0 deletions tests/neg/i19100.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.language.future

def test =
<foo/> match // error
case <foo/> => 1 // error
<bar></bar> // error

0 comments on commit dd105da

Please sign in to comment.