Description
In Scala 2 this code
for {
(a, b) <- Right("" -> 1)
} yield ()
fails to compile with error
value
withFilter
is not a member ofscala.util.Right[Nothing,(String, Int)]
(unless you use better-monadic-for plugin)
In Scala 3, it compiles fine.
I found these related links:
- Scala Wart: Conflating total destructuring with partial pattern-matching #2578
- Fix #2578: (part 2) Make for-generators filter only if prefixed with
case
. #6448 - Enable stricter pattern binding warnings by default #14294
- In 3.4 make refutable patterns in a for comprehension an error #18842
- https://contributors.scala-lang.org/t/pre-sip-improve-for-comprehensions-functionality/3509
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