Skip to content

Tighten requirements for migration mode #11619

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

Merged
merged 4 commits into from
Mar 8, 2021
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
34 changes: 17 additions & 17 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ object Parsers {
} :: contextBounds(pname)
case VIEWBOUND =>
report.errorOrMigrationWarning(
"view bounds `<%' are deprecated, use a context bound `:' instead",
"view bounds `<%' are no longer supported, use a context bound `:' instead",
in.sourcePos())
atSpan(in.skipToken()) {
Function(Ident(pname) :: Nil, toplevelTyp())
Expand Down Expand Up @@ -2084,10 +2084,10 @@ object Parsers {
val isVarargSplice = location.inArgs && followingIsVararg()
in.nextToken()
if isVarargSplice then
if sourceVersion.isAtLeast(future) then
report.errorOrMigrationWarning(
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead${rewriteNotice("future")}",
in.sourcePos(uscoreStart))
report.errorOrMigrationWarning(
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead${rewriteNotice("future")}",
in.sourcePos(uscoreStart),
future)
if sourceVersion == `future-migration` then
patch(source, Span(t.span.end, in.lastOffset), " *")
else if opStack.nonEmpty then
Expand Down Expand Up @@ -2162,12 +2162,10 @@ object Parsers {
val name = bindingName()
val t =
if (in.token == COLON && location == Location.InBlock) {
if sourceVersion.isAtLeast(future) then
// Don't error in non-strict mode, as the alternative syntax "implicit (x: T) => ... "
// is not supported by Scala2.x
report.errorOrMigrationWarning(
s"This syntax is no longer supported; parameter needs to be enclosed in (...)${rewriteNotice("future")}",
source.atSpan(Span(start, in.lastOffset)))
report.errorOrMigrationWarning(
s"This syntax is no longer supported; parameter needs to be enclosed in (...)${rewriteNotice("future")}",
source.atSpan(Span(start, in.lastOffset)),
from = future)
in.nextToken()
val t = infixType()
if (sourceVersion == `future-migration`) {
Expand Down Expand Up @@ -2665,10 +2663,10 @@ object Parsers {
p

private def warnStarMigration(p: Tree) =
if sourceVersion.isAtLeast(future) then
report.errorOrMigrationWarning(
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead",
in.sourcePos(startOffset(p)))
report.errorOrMigrationWarning(
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead",
in.sourcePos(startOffset(p)),
from = future)

/** InfixPattern ::= SimplePattern {id [nl] SimplePattern}
*/
Expand Down Expand Up @@ -3124,7 +3122,8 @@ object Parsers {
if in.token == USCORE && sourceVersion.isAtLeast(future) then
report.errorOrMigrationWarning(
em"`_` is no longer supported for a wildcard import; use `*` instead${rewriteNotice("future")}",
in.sourcePos())
in.sourcePos(),
from = future)
patch(source, Span(in.offset, in.offset + 1), "*")
ImportSelector(atSpan(in.skipToken()) { Ident(nme.WILDCARD) })

Expand All @@ -3142,7 +3141,8 @@ object Parsers {
if in.token == ARROW && sourceVersion.isAtLeast(future) then
report.errorOrMigrationWarning(
em"The import renaming `a => b` is no longer supported ; use `a as b` instead${rewriteNotice("future")}",
in.sourcePos())
in.sourcePos(),
from = future)
patch(source, Span(in.offset, in.offset + 2),
if testChar(in.offset - 1, ' ') && testChar(in.offset + 2, ' ') then "as"
else " as ")
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object report:
def errorOrMigrationWarning(msg: Message, pos: SrcPos = NoSourcePosition,
from: SourceVersion = SourceVersion.defaultSourceVersion)(using Context): Unit =
if sourceVersion.isAtLeast(from) then
if sourceVersion.isMigrating then migrationWarning(msg, pos)
if sourceVersion.isMigrating && sourceVersion.ordinal <= from.ordinal then migrationWarning(msg, pos)
else error(msg, pos)

def restrictionError(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/NonLocalReturns.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ class NonLocalReturns extends MiniPhase {

override def transformReturn(tree: Return)(using Context): Tree =
if isNonLocalReturn(tree) then
if sourceVersion.isAtLeast(future) then
report.errorOrMigrationWarning("Non local returns are no longer supported; use scala.util.control.NonLocalReturns instead", tree.srcPos)
report.errorOrMigrationWarning(
"Non local returns are no longer supported; use scala.util.control.NonLocalReturns instead",
tree.srcPos,
from = future)
nonLocalReturnThrow(tree.expr, tree.from.symbol).withSpan(tree.span)
else tree
}
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2472,8 +2472,11 @@ class Typer extends Namer
def remedy =
if ((prefix ++ suffix).isEmpty) "simply leave out the trailing ` _`"
else s"use `$prefix<function>$suffix` instead"
report.errorOrMigrationWarning(i"""The syntax `<function> _` is no longer supported;
|you can $remedy""", tree.srcPos, future)
report.errorOrMigrationWarning(
i"""The syntax `<function> _` is no longer supported;
|you can $remedy""",
tree.srcPos,
from = future)
if sourceVersion.isMigrating then
patch(Span(tree.span.start), prefix)
patch(Span(qual.span.end, tree.span.end), suffix)
Expand Down
3 changes: 2 additions & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ class CompilationTests {
compileFile("tests/neg-custom-args/i5498-postfixOps.scala", defaultOptions withoutLanguageFeature "postfixOps"),
compileFile("tests/neg-custom-args/deptypes.scala", defaultOptions.and("-language:experimental.dependent")),
compileFile("tests/neg-custom-args/matchable.scala", defaultOptions.and("-Xfatal-warnings", "-source", "future")),
compileFile("tests/neg-custom-args/i7314.scala", defaultOptions.and("-Xfatal-warnings", "-source", "future"))
compileFile("tests/neg-custom-args/i7314.scala", defaultOptions.and("-Xfatal-warnings", "-source", "future")),
compileFile("tests/neg-custom-args/feature-shadowing.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
).checkExpectedErrors()
}

Expand Down
13 changes: 13 additions & 0 deletions tests/neg-custom-args/feature-shadowing.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import language.implicitConversions
given Conversion[Int, String] = _.toString

object a:
val s: String = 1 // OK

object b:
import language.implicitConversions as _
val s: String = 2 // error

object c:
import language.implicitConversions
val s: String = 3 // OK again
5 changes: 5 additions & 0 deletions tests/neg/i11567.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import language.`future-migration`
class Test
object Test {
def foo[A <% Test](x: A) = x // error
}