Skip to content

Commit 7a39864

Browse files
committed
Refine isFunction criterion
1 parent 940e771 commit 7a39864

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
329329
def isFunctionWithUnknownParamType(tree: Tree): Boolean =
330330
functionWithUnknownParamType(tree).isDefined
331331

332+
def isFunction(tree: Tree): Boolean = tree match
333+
case Function(_, _) | Match(EmptyTree, _) => true
334+
case Block(Nil, expr) => isFunction(expr)
335+
case _ => false
336+
332337
/** Is `tree` an context function or closure, possibly nested in a block? */
333338
def isContextualClosure(tree: Tree)(using Context): Boolean = unsplice(tree) match {
334339
case tree: FunctionWithMods => tree.mods.is(Given)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,8 +3831,7 @@ class Typer extends Namer
38313831
&& !isSelfOrSuperConstrCall(tree)
38323832
then tree match
38333833
case closureDef(meth)
3834-
if meth.span == meth.rhs.span.toSynthetic
3835-
&& !original.isInstanceOf[untpd.Function] =>
3834+
if meth.span == meth.rhs.span.toSynthetic && !untpd.isFunction(original) =>
38363835
// It's a synthesized lambda, for instance via an eta expansion: report a hard error
38373836
// There are two tests for synthetic lambdas which both have to be true.
38383837
// The first test compares spans of closure definition with the closure's right hand

0 commit comments

Comments
 (0)