@@ -1352,7 +1352,7 @@ class Typer extends Namer
1352
1352
else cpy.ValDef (param)(
1353
1353
tpt = untpd.TypeTree (
1354
1354
inferredParamType(param, protoFormal(i)).translateFromRepeated(toArray = false )))
1355
- desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual)
1355
+ desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual, tree.span )
1356
1356
}
1357
1357
typed(desugared, pt)
1358
1358
}
@@ -3110,12 +3110,9 @@ class Typer extends Namer
3110
3110
def readapt (tree : Tree , shouldTryGadtHealing : Boolean = tryGadtHealing)(using Context ) = adapt(tree, pt, locked, shouldTryGadtHealing)
3111
3111
def readaptSimplified (tree : Tree )(using Context ) = readapt(simplify(tree, pt, locked))
3112
3112
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)
3117
3115
tree.withType(mt.resultType)
3118
- }
3119
3116
3120
3117
def adaptOverloaded (ref : TermRef ) = {
3121
3118
val altDenots =
@@ -3409,19 +3406,19 @@ class Typer extends Namer
3409
3406
// - we reference a typelevel method
3410
3407
// - we are in a pattern
3411
3408
// - 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
3417
3415
if (! defn.isFunctionType(pt))
3418
3416
pt match {
3419
3417
case SAMType (_) if ! pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot ) =>
3420
3418
report.warning(ex " ${tree.symbol} is eta-expanded even though $pt does not have the @FunctionalInterface annotation. " , tree.srcPos)
3421
3419
case _ =>
3422
3420
}
3423
3421
simplify(typed(etaExpand(tree, wtp, arity), pt), pt, locked)
3424
- }
3425
3422
else if (wtp.paramInfos.isEmpty && isAutoApplied(tree.symbol))
3426
3423
readaptSimplified(tpd.Apply (tree, Nil ))
3427
3424
else if (wtp.isImplicitMethod)
@@ -3841,8 +3838,20 @@ class Typer extends Namer
3841
3838
&& ! tree.isInstanceOf [Inlined ]
3842
3839
&& isPureExpr(tree)
3843
3840
&& ! 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)
3846
3855
3847
3856
/** Types the body Scala 2 macro declaration `def f = macro <body>` */
3848
3857
private def typedScala2MacroBody (call : untpd.Tree )(using Context ): Tree =
0 commit comments