Skip to content

Commit 0cb2dd3

Browse files
committed
Patch redundant `_' suffixes.
Scala2 allows `x _` even if `x` is not a method. Dotty disallows them. The patch removes the ` _` in these cases.
1 parent 4e10b72 commit 0cb2dd3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import annotation.tailrec
3333
import Implicits._
3434
import util.Stats.{track, record}
3535
import config.Printers._
36+
import rewrite.Rewrites.patch
3637
import language.implicitConversions
3738

3839
object Typer {
@@ -1134,13 +1135,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
11341135
}
11351136
}
11361137

1137-
def typedAsFunction(tree: untpd.Tree, pt: Type)(implicit ctx: Context): Tree = {
1138+
def typedAsFunction(tree: untpd.PostfixOp, pt: Type)(implicit ctx: Context): Tree = {
1139+
val untpd.PostfixOp(qual, nme.WILDCARD) = tree
11381140
val pt1 = if (defn.isFunctionType(pt)) pt else AnyFunctionProto
1139-
var res = typed(tree, pt1)
1141+
var res = typed(qual, pt1)
11401142
if (pt1.eq(AnyFunctionProto) && !defn.isFunctionClass(res.tpe.classSymbol)) {
11411143
def msg = i"not a function: ${res.tpe}; cannot be followed by `_'"
11421144
if (ctx.scala2Mode) {
11431145
ctx.migrationWarning(msg, tree.pos)
1146+
patch(ctx.compilationUnit.source, Position(qual.pos.end, tree.pos.end), "")
11441147
res = typed(untpd.Function(Nil, untpd.TypedSplice(res)))
11451148
}
11461149
else ctx.error(msg, tree.pos)
@@ -1231,7 +1234,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
12311234
case tree: untpd.Annotated => typedAnnotated(tree, pt)
12321235
case tree: untpd.TypedSplice => tree.tree
12331236
case tree: untpd.UnApply => typedUnApply(tree, pt)
1234-
case untpd.PostfixOp(tree, nme.WILDCARD) => typedAsFunction(tree, pt)
1237+
case tree @ untpd.PostfixOp(qual, nme.WILDCARD) => typedAsFunction(tree, pt)
12351238
case untpd.EmptyTree => tpd.EmptyTree
12361239
case _ => typedUnadapted(desugar(tree), pt)
12371240
}

0 commit comments

Comments
 (0)