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