Skip to content

Commit 4df21b0

Browse files
committed
Offer rewriting to new import syntax
1 parent d269a8d commit 4df21b0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -3115,6 +3115,11 @@ object Parsers {
31153115

31163116
/** ‘*' | ‘_' */
31173117
def wildcardSelector() =
3118+
if in.token == USCORE && sourceVersion.isAtLeast(`3.1`) then
3119+
report.errorOrMigrationWarning(
3120+
em"`_` is no longer supported for a wildcard import; use `*` instead${rewriteNotice("3.1")}",
3121+
in.sourcePos())
3122+
patch(source, Span(in.offset, in.offset + 1), "*")
31183123
ImportSelector(atSpan(in.skipToken()) { Ident(nme.WILDCARD) })
31193124

31203125
/** 'given [InfixType]' */
@@ -3128,6 +3133,13 @@ object Parsers {
31283133
/** id [‘as’ (id | ‘_’) */
31293134
def namedSelector(from: Ident) =
31303135
if in.token == ARROW || isIdent(nme.as) then
3136+
if in.token == ARROW && sourceVersion.isAtLeast(`3.1`) then
3137+
report.errorOrMigrationWarning(
3138+
em"The import renaming `a => b` is no longer supported ; use `a as b` instead${rewriteNotice("3.1")}",
3139+
in.sourcePos())
3140+
patch(source, Span(in.offset, in.offset + 2),
3141+
if testChar(in.offset - 1, ' ') && testChar(in.offset + 2, ' ') then "as"
3142+
else " as ")
31313143
atSpan(startOffset(from), in.skipToken()) {
31323144
val to = if in.token == USCORE then wildcardIdent() else termIdent()
31333145
ImportSelector(from, if to.name == nme.ERROR then EmptyTree else to)

tests/rewrites/rewrites3x.scala

+4-1
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)