Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
unkarjedy opened this issue Apr 26, 2024 · 1 comment · May be fixed by #21702
Open

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

unkarjedy opened this issue Apr 26, 2024 · 1 comment · May be fixed by #21702

Comments

@unkarjedy
Copy link
Contributor

unkarjedy commented Apr 26, 2024

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

@unkarjedy unkarjedy added the stat:needs triage Every issue needs to have an "area" and "itype" label label Apr 26, 2024
@unkarjedy unkarjedy closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2024
@unkarjedy unkarjedy reopened this Apr 26, 2024
@unkarjedy
Copy link
Contributor Author

Related IntelliJ ticket
https://youtrack.jetbrains.com/issue/SCL-22468

@sjrd sjrd self-assigned this Apr 29, 2024
@sjrd sjrd added area:spec and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 29, 2024
sjrd added a commit to dotty-staging/dotty that referenced this issue Oct 4, 2024
Since Scala 3.4, a `withFilter` is generated if and only if the
generator has the `case` modifier.

If it does not, the pattern must be irrefutable.
@sjrd sjrd linked a pull request Oct 4, 2024 that will close this issue
sjrd added a commit to dotty-staging/dotty that referenced this issue Oct 5, 2024
Since Scala 3.4, a `withFilter` is generated if and only if the
generator has the `case` modifier.

If it does not, the pattern must be irrefutable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants