@@ -1548,17 +1548,21 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
15481548 def typedAsFunction (tree : untpd.PostfixOp , pt : Type )(implicit ctx : Context ): Tree = {
15491549 val untpd .PostfixOp (qual, Ident (nme.WILDCARD )) = tree
15501550 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+ }
15601563 }
1561- else if (ctx.settings.strict.value) {
1564+ nestedCtx.typerState.commit()
1565+ if (ctx.settings.strict.value) {
15621566 lazy val (prefix, suffix) = res match {
15631567 case Block (mdef @ DefDef (_, _, vparams :: Nil , _, _) :: Nil , _ : Closure ) =>
15641568 val arity = vparams.length
0 commit comments