@@ -1352,7 +1352,7 @@ class Typer extends Namer
13521352 else cpy.ValDef (param)(
13531353 tpt = untpd.TypeTree (
13541354 inferredParamType(param, protoFormal(i)).translateFromRepeated(toArray = false )))
1355- desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual)
1355+ desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual, tree.span )
13561356 }
13571357 typed(desugared, pt)
13581358 }
@@ -3110,12 +3110,9 @@ class Typer extends Namer
31103110 def readapt (tree : Tree , shouldTryGadtHealing : Boolean = tryGadtHealing)(using Context ) = adapt(tree, pt, locked, shouldTryGadtHealing)
31113111 def readaptSimplified (tree : Tree )(using Context ) = readapt(simplify(tree, pt, locked))
31123112
3113- def missingArgs (mt : MethodType ) = {
3114- val meth = err.exprStr(methPart(tree))
3115- if (mt.paramNames.length == 0 ) report.error(MissingEmptyArgumentList (meth), tree.srcPos)
3116- else report.error(em " missing arguments for $meth" , tree.srcPos)
3113+ def missingArgs (mt : MethodType ) =
3114+ ErrorReporting .missingArgs(tree, mt)
31173115 tree.withType(mt.resultType)
3118- }
31193116
31203117 def adaptOverloaded (ref : TermRef ) = {
31213118 val altDenots =
@@ -3409,19 +3406,19 @@ class Typer extends Namer
34093406 // - we reference a typelevel method
34103407 // - we are in a pattern
34113408 // - the current tree is a synthetic apply which is not expandable (eta-expasion would simply undo that)
3412- if (arity >= 0 &&
3413- ! tree.symbol.isConstructor &&
3414- ! tree.symbol.isAllOf(InlineMethod ) &&
3415- ! ctx.mode.is(Mode .Pattern ) &&
3416- ! (isSyntheticApply(tree) && ! functionExpected)) {
3409+ if arity >= 0
3410+ && ! tree.symbol.isConstructor
3411+ && ! tree.symbol.isAllOf(InlineMethod )
3412+ && ! ctx.mode.is(Mode .Pattern )
3413+ && ! (isSyntheticApply(tree) && ! functionExpected)
3414+ then
34173415 if (! defn.isFunctionType(pt))
34183416 pt match {
34193417 case SAMType (_) if ! pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot ) =>
34203418 report.warning(ex " ${tree.symbol} is eta-expanded even though $pt does not have the @FunctionalInterface annotation. " , tree.srcPos)
34213419 case _ =>
34223420 }
34233421 simplify(typed(etaExpand(tree, wtp, arity), pt), pt, locked)
3424- }
34253422 else if (wtp.paramInfos.isEmpty && isAutoApplied(tree.symbol))
34263423 readaptSimplified(tpd.Apply (tree, Nil ))
34273424 else if (wtp.isImplicitMethod)
@@ -3841,8 +3838,20 @@ class Typer extends Namer
38413838 && ! tree.isInstanceOf [Inlined ]
38423839 && isPureExpr(tree)
38433840 && ! isSelfOrSuperConstrCall(tree)
3844- then
3845- report.warning(PureExpressionInStatementPosition (original, exprOwner), original.srcPos)
3841+ then tree match
3842+ case closureDef(meth)
3843+ if meth.span == meth.rhs.span.toSynthetic && ! untpd.isFunction(original) =>
3844+ // It's a synthesized lambda, for instance via an eta expansion: report a hard error
3845+ // There are two tests for synthetic lambdas which both have to be true.
3846+ // The first test compares spans of closure definition with the closure's right hand
3847+ // side. This is usually accurate but can fail for compiler-generated test code.
3848+ // See repl.DocTests for two failing tests. The second tests rules out closures
3849+ // if the original tree was a lambda. This does not work always either since
3850+ // sometimes we do not have the original anymore and use the transformed tree instead.
3851+ // But taken together, the two criteria are quite accurate.
3852+ missingArgs(tree, tree.tpe.widen)
3853+ case _ =>
3854+ report.warning(PureExpressionInStatementPosition (original, exprOwner), original.srcPos)
38463855
38473856 /** Types the body Scala 2 macro declaration `def f = macro <body>` */
38483857 private def typedScala2MacroBody (call : untpd.Tree )(using Context ): Tree =
0 commit comments