diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 159ce8354a30..c4c3f6b2d439 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -4569,7 +4569,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer // convert function literal to SAM closure tree match { - case closure(Nil, id @ Ident(nme.ANON_FUN), _) + case blockEndingInClosure(Nil, id @ Ident(nme.ANON_FUN), _) if defn.isFunctionNType(wtp) && !defn.isFunctionNType(pt) => pt match { case SAMType(samMeth, samParent) @@ -4578,6 +4578,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer // but this prevents case blocks from implementing polymorphic partial functions, // since we do not know the result parameter a priori. Have to wait until the // body is typechecked. + // Note: Need to come back to this when we clean up SAMs/PartialFunctions + // These conditions would most likely be affected by a precise spec. return toSAM(tree, samParent) case _ => } diff --git a/tests/pos/i21676.scala b/tests/pos/i21676.scala new file mode 100644 index 000000000000..2f94fda47be5 --- /dev/null +++ b/tests/pos/i21676.scala @@ -0,0 +1,18 @@ +def Test = + val members = collection.immutable.SortedSet.empty[String] + members.collect { + var upNumber = 0 + { + case m => + // upNumber += 1 + m + } + } + + members.collect { + var upNumber = 0 + { + m => m + } + } +