withFilter required for irrefutable for comprehension pattern
See original GitHub issueTuple decomposition seems to have regressed in some cases. The following works fine under 3.1.3
Compiler version
3.2.0-RC1
Minimized code
//> using scala "3.2.0-RC1"
//> using option "-source:future"
//> using option "-Ykind-projector"
//> using lib "org.typelevel::cats-effect::3.3.13"
import cats.Monad
import cats.effect.Temporal
import cats.syntax.all.*
trait ProjectionStore[F[_], State, Output]:
def loadRecent: F[(Int, Option[State])]
def test[F[_]: Temporal](store: ProjectionStore[F, Int, Int]) =
for (x, y) <- store.loadRecent
yield println(s"x: $x, y: $y")
Output
[error] ./t.scala:14:17: value withFilter is not a member of F[(Int, Option[Int])]
[error]
[error] where: F is a type in method test with bounds <: [_] =>> Any
[error] for (x, y) <- store.loadRecent
[error] ^^^^^^^^^^^^^^^^
Error compiling project (Scala 3.2.0-RC1, JVM)
Compilation failed
Expectation
Compilation passes
Issue Analytics
- State:
- Created a year ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
why does filter have to be defined for pattern matching in a for ...
So the first example is easy for the compiler to determine that withFilter is not required. Your second example is potentially the third...
Read more >for-comprehension expansion when using pattern matching
It is confusing because there's no reason a total destructuring (sometimes called a "irrefutable pattern") should result in a .withFilter ...
Read more >typelevel/cats - Gitter
I wish I could have a bit more syntax in for comprehensions. a = ... at the beginning, _ <- a without noise,...
Read more >Either for-comprehension different behavior in 2.9 and 2.10 ...
Coding example for the question Either for-comprehension different ... In your first case, p is Irrefutable (Point-1 in spec) so withFilter is not...
Read more >The power of monads and for comprehensions - Medium
All we need is to implement the operations map , flatMap , and withFilter to make it usable in a for comprehension. Let's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the issue is that these patterns should not be considered refutable
😳
PR: https://github.com/lampepfl/dotty/pull/15593
Thanks for testing the RC and catching this!