@@ -1548,17 +1548,21 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1548
1548
def typedAsFunction (tree : untpd.PostfixOp , pt : Type )(implicit ctx : Context ): Tree = {
1549
1549
val untpd .PostfixOp (qual, Ident (nme.WILDCARD )) = tree
1550
1550
val pt1 = if (defn.isFunctionType(pt)) pt else AnyFunctionProto
1551
- var res = typed(qual, pt1)
1552
- if (pt1.eq(AnyFunctionProto ) && ! defn.isFunctionClass(res.tpe.classSymbol)) {
1553
- ctx.errorOrMigrationWarning(OnlyFunctionsCanBeFollowedByUnderscore (res.tpe), tree.pos)
1554
- if (ctx.scala2Mode) {
1555
- // Under -rewrite, patch `x _` to `(() => x)`
1556
- patch(Position (tree.pos.start), " (() => " )
1557
- patch(Position (qual.pos.end, tree.pos.end), " )" )
1558
- res = typed(untpd.Function (Nil , untpd.TypedSplice (res)))
1559
- }
1551
+ val nestedCtx = ctx.fresh.setNewTyperState()
1552
+ val res = typed(qual, pt1)(nestedCtx)
1553
+ res match {
1554
+ case res @ closure(_, _, _) =>
1555
+ case _ =>
1556
+ ctx.errorOrMigrationWarning(OnlyFunctionsCanBeFollowedByUnderscore (res.tpe), tree.pos)
1557
+ if (ctx.scala2Mode) {
1558
+ // Under -rewrite, patch `x _` to `(() => x)`
1559
+ patch(Position (tree.pos.start), " (() => " )
1560
+ patch(Position (qual.pos.end, tree.pos.end), " )" )
1561
+ return typed(untpd.Function (Nil , qual), pt)
1562
+ }
1560
1563
}
1561
- else if (ctx.settings.strict.value) {
1564
+ nestedCtx.typerState.commit()
1565
+ if (ctx.settings.strict.value) {
1562
1566
lazy val (prefix, suffix) = res match {
1563
1567
case Block (mdef @ DefDef (_, _, vparams :: Nil , _, _) :: Nil , _ : Closure ) =>
1564
1568
val arity = vparams.length
0 commit comments