From 7bbed2b0a73e9c4aef9fedf6473a319431a7df7f Mon Sep 17 00:00:00 2001 From: odersky Date: Tue, 1 Oct 2024 15:24:46 +0200 Subject: [PATCH] Revert SAM condition to what it was before Fixes #21676 --- .../src/dotty/tools/dotc/typer/Typer.scala | 4 +++- tests/pos/i21676.scala | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i21676.scala 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 + } + } +