Skip to content

Commit 01a12df

Browse files
committed
Make more anonymous functions static
An anonymous function in a static object was previously mapped to a member of that object. We now map it to a static member of the toplevel class instead. This causes the backend to memoize the function, which fixes scala#19224. On the other hand, we don't do that for anonymous functions nested in the object constructor, since that can cause deadlocks (see run/deadlock.scala). Scala 2's behavior is different: it does lift lambdas in constructors to be static, too, which can cause deadlocks. Fixes scala#19924
1 parent 4e6de64 commit 01a12df

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

tests/run/i19224.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ object Test extends App:
44
def x(): Int => String = (i: Int) => i.toString
55
def y(): () => String = () => field.toString
66
locally:
7-
assert(x() == x()) // was true on Scala 2, false on Scala 3...
7+
assert(x() == x()) // true on Scala 2, was false on Scala 3...
88
assert(y() == y()) // also true if `y` accesses object-local fields
99

10-
11-
//@main def Test = App()

0 commit comments

Comments
 (0)