Skip to content

Commit 940e771

Browse files
committed
Refine condition when a lambda is synthetic
1 parent 003eaca commit 940e771

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,8 +3830,17 @@ class Typer extends Namer
38303830
&& isPureExpr(tree)
38313831
&& !isSelfOrSuperConstrCall(tree)
38323832
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.
38353844
missingArgs(tree, tree.tpe.widen)
38363845
case _ =>
38373846
report.warning(PureExpressionInStatementPosition(original, exprOwner), original.srcPos)

0 commit comments

Comments
 (0)