Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert SAM condition to what it was before #21684

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}

Loading