Skip to content

Language Spec: add more details about changes in for comprehension #20271

Closed
@unkarjedy

Description

@unkarjedy

In Scala 2 this code

for {
  (a, b) <- Right("" -> 1)
} yield ()

fails to compile with error

value withFilter is not a member of scala.util.Right[Nothing,(String, Int)]

(unless you use better-monadic-for plugin)

In Scala 3, it compiles fine.
I found these related links:

There is a lot of information spread around multiple links, and it's hard to understand current behaviour or current desired behavior (these two proved to be different things)
I couldn't find any section in the language specification which would cover the latest state of affairs (specifically the part about withFilter).
I see "Other Changed Features | Pattern Bindings", but I don't see anything related to withFilter.
The page mostly mentions how Scala 3 produces warning/error in the code, which would be fine in Scala 2 but not vice versa.

Can you please add more details about withFilter.
Maybe the page misses something else.
The withFilter part attracted my attention due to
https://youtrack.jetbrains.com/issue/SCL-22274/Destructured-types-are-not-inferred-in-for-comprehension-for-ZIO


UPD
I also found https://scala-lang.org/blog/2024/02/29/scala-3.4.0-and-3.3.3-released.html
Blog posts are helpful and can shed light on many things.
But to be 100% sure about the latest behaviour you need to process them one by one, collecting all the changes and calculating what is relevant and what is not relevant

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions