Skip to content

Pattern decomposition failing in for comprehension for Either #17216

Closed
@Andrapyre

Description

@Andrapyre

Compiler version

3.2.0. Also tried 3.3.0-RC2 and found the same bug.

Cats Effect version

3.4.8

Minimized code

import cats.effect.IO

val someIOOp: IO[(Int, String)] = IO.pure((1,"sample"))

for {
  (num, str) <- someIOOp
} yield ()

Output

[error] 44 |      (num, str) <- someIOOp
[error]    |                    ^^^^^^^^
[error]    |       value withFilter is not a member of cats.effect.IO[(Int, String)]

Expectation

Expected that decomposition would succeed inside the for comprehension and that num and str would be parsed to Int and String respectively. The compiler parses a normal flatMap call correctly. So the following correctly returns the number:

someIOOp.flatMap { (num, str) =>
  IO(num)
}

It's just decomposition inside the for comprehension that fails for the IO. This bug does not affect Option, but it does affect Either, since Either lacks the .withFilter method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:desugarDesugaring happens after parsing but before typing, see desugar.scalaitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions