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 @@ -3830,8 +3830,17 @@ class Typer extends Namer
3830
3830
&& isPureExpr(tree)
3831
3831
&& ! isSelfOrSuperConstrCall(tree)
3832
3832
then tree match
3833
- case closureDef(meth) if meth.span == meth.rhs.span.toSynthetic =>
3834
- // it's a synthesized lambda, for instance via an eta expansion: report a hard error
3833
+ case closureDef(meth)
3834
+ if meth.span == meth.rhs.span.toSynthetic
3835
+ && ! original.isInstanceOf [untpd.Function ] =>
3836
+ // It's a synthesized lambda, for instance via an eta expansion: report a hard error
3837
+ // There are two tests for synthetic lambdas which both have to be true.
3838
+ // The first test compares spans of closure definition with the closure's right hand
3839
+ // side. This is usually accurate but can fail for compiler-generated test code.
3840
+ // See repl.DocTests for two failing tests. The second tests rules out closures
3841
+ // if the original tree was a lambda. This does not work always either since
3842
+ // sometimes we do not have the original anymore and use the transformed tree instead.
3843
+ // But taken together, the two criteria are quite accurate.
3835
3844
missingArgs(tree, tree.tpe.widen)
3836
3845
case _ =>
3837
3846
report.warning(PureExpressionInStatementPosition (original, exprOwner), original.srcPos)
You can’t perform that action at this time.
0 commit comments