Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migration warning for XML literals in language future #19101

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 // FIXME should be `curOffset - 1` (scalatest and tests/neg/i19100.scala must be updated)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EugeneFlesselle started working on updating the scalatest submodule. I will fix this once the submodule is updated to avoid conflicts.

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 // FIXME should be `curOffset - 1` (scalatest and tests/neg/i19100.scala must be updated)
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:3 -----------------------------------------------------------------------------------
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:10 ----------------------------------------------------------------------------------
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:3 -----------------------------------------------------------------------------------
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
Loading