File tree 1 file changed +11
-2
lines changed
compiler/src/dotty/tools/dotc/typer
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -3823,8 +3823,17 @@ class Typer extends Namer
3823
3823
&& isPureExpr(tree)
3824
3824
&& ! isSelfOrSuperConstrCall(tree)
3825
3825
then tree match
3826
- case closureDef(meth) if meth.span == meth.rhs.span.toSynthetic =>
3827
- // it's a synthesized lambda, for instance via an eta expansion: report a hard error
3826
+ case closureDef(meth)
3827
+ if meth.span == meth.rhs.span.toSynthetic
3828
+ && ! original.isInstanceOf [untpd.Function ] =>
3829
+ // It's a synthesized lambda, for instance via an eta expansion: report a hard error
3830
+ // There are two tests for synthetic lambdas which both have to be true.
3831
+ // The first test compares spans of closure definition with the closure's right hand
3832
+ // side. This is usually accurate but can fail for compiler-generated test code.
3833
+ // See repl.DocTests for two failing tests. The second tests rules out closures
3834
+ // if the original tree was a lambda. This does not work always either since
3835
+ // sometimes we do not have the original anymore and use the transformed tree instead.
3836
+ // But taken together, the two criteria are quite accurate.
3828
3837
missingArgs(tree, tree.tpe.widen)
3829
3838
case _ =>
3830
3839
report.warning(PureExpressionInStatementPosition (original, exprOwner), original.srcPos)
You can’t perform that action at this time.
0 commit comments