-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
8 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
// scalajs: --skip | ||
|
||
object Test extends App: | ||
object Test extends App { | ||
val field = 1 | ||
def x(): Int => String = (i: Int) => i.toString | ||
def y(): () => String = () => field.toString | ||
locally: | ||
|
||
locally { | ||
assert(x() == x()) // true on Scala 2, was false on Scala 3... | ||
assert(y() == y()) // also true if `y` accesses object-local fields | ||
|
||
def z(): Int => String = (i: Int) => i.toString | ||
assert(z() != z()) // lambdas in constructor are not lifted to static, so no memoization (Scala 2 lifts them, though). | ||
} | ||
} |