-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
for loops in Scala 3 (and 2.x) support guards, however the following does not compile:
def getNums(): UIO[List[Int]] = ZIO.succeed(List(1, 2, 3))
def printNum(n: Int): UIO[Unit] = ZIO.succeed(println(n))
defer {
for {
n <- getNums().run
if n % 2 == 0
} printNum(n).run // Error: While expanding a macro, a reference to parameter n
} // was used outside the scope where it was definedIt seems it has something to do with how guards are desugared, the following also doesn't compile:
defer {
getNums().run.withFilter(n => n % 2 == 0).foreach(n => printNum(n).run)
}whereas replacing withFilter with filter successfully compiles.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels