Skip to content

Commit

Permalink
Revert SAM condition to what it was before
Browse files Browse the repository at this point in the history
Fixes #21676
  • Loading branch information
odersky committed Oct 1, 2024
1 parent 56a384f commit 7bbed2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 _ =>
}
Expand Down
18 changes: 18 additions & 0 deletions tests/pos/i21676.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 7bbed2b

Please sign in to comment.