Skip to content

Commit 8445d3c

Browse files
committed
Offer rewriting to new import syntax
1 parent bc6ff3f commit 8445d3c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,6 +3111,11 @@ object Parsers {
31113111

31123112
/** ‘*' | ‘_' */
31133113
def wildcardSelector() =
3114+
if in.token == USCORE && sourceVersion.isAtLeast(`3.1`) then
3115+
report.errorOrMigrationWarning(
3116+
em"`_` is no longer supported for a wildcard import; use `*` instead${rewriteNotice("3.1")}",
3117+
in.sourcePos())
3118+
patch(source, Span(in.offset, in.offset + 1), "*")
31143119
ImportSelector(atSpan(in.skipToken()) { Ident(nme.WILDCARD) })
31153120

31163121
/** 'given [InfixType]' */
@@ -3124,6 +3129,13 @@ object Parsers {
31243129
/** id [‘as’ (id | ‘_’) */
31253130
def namedSelector(from: Ident) =
31263131
if in.token == ARROW || isIdent(nme.as) then
3132+
if in.token == ARROW && sourceVersion.isAtLeast(`3.1`) then
3133+
report.errorOrMigrationWarning(
3134+
em"The import renaming `a => b` is no longer supported ; use `a as b` instead${rewriteNotice("3.1")}",
3135+
in.sourcePos())
3136+
patch(source, Span(in.offset, in.offset + 2),
3137+
if testChar(in.offset - 1, ' ') && testChar(in.offset + 2, ' ') then "as"
3138+
else " as ")
31273139
atSpan(startOffset(from), in.skipToken()) {
31283140
val to = if in.token == USCORE then wildcardIdent() else termIdent()
31293141
ImportSelector(from, if to.name == nme.ERROR then EmptyTree else to)

tests/rewrites/rewrites3x.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import scala.{collection => coll, runtime=>_, _}
2+
import coll._
3+
14
def f(xs: Int*) = xs.sum
25
def test =
3-
f(List(1, 2, 3) *)
6+
f(List(1, 2, 3): _*)
47

58
def g = { implicit x: Int =>
69
x + 1

0 commit comments

Comments
 (0)