question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

withFilter required for irrefutable for comprehension pattern

See original GitHub issue

Tuple 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:closed
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
bishaboshacommented, Jul 4, 2022

I think the issue is that these patterns should not be considered refutable

1reaction
griggtcommented, Jul 5, 2022

😳

PR: https://github.com/lampepfl/dotty/pull/15593

Thanks for testing the RC and catching this!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found