Skip to content

Commit b7828ac

Browse files
authored
Revert SAM condition to what it was before (#21684)
Fixes #21676
2 parents 3408ed7 + 7bbed2b commit b7828ac

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4568,7 +4568,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
45684568

45694569
// convert function literal to SAM closure
45704570
tree match {
4571-
case closure(Nil, id @ Ident(nme.ANON_FUN), _)
4571+
case blockEndingInClosure(Nil, id @ Ident(nme.ANON_FUN), _)
45724572
if defn.isFunctionNType(wtp) && !defn.isFunctionNType(pt) =>
45734573
pt match {
45744574
case SAMType(samMeth, samParent)
@@ -4577,6 +4577,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
45774577
// but this prevents case blocks from implementing polymorphic partial functions,
45784578
// since we do not know the result parameter a priori. Have to wait until the
45794579
// body is typechecked.
4580+
// Note: Need to come back to this when we clean up SAMs/PartialFunctions
4581+
// These conditions would most likely be affected by a precise spec.
45804582
return toSAM(tree, samParent)
45814583
case _ =>
45824584
}

tests/pos/i21676.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def Test =
2+
val members = collection.immutable.SortedSet.empty[String]
3+
members.collect {
4+
var upNumber = 0
5+
{
6+
case m =>
7+
// upNumber += 1
8+
m
9+
}
10+
}
11+
12+
members.collect {
13+
var upNumber = 0
14+
{
15+
m => m
16+
}
17+
}
18+

0 commit comments

Comments
 (0)