Skip to content

For comprehension desugaring different when pattern not enclosed in parentheses #24736

@OndrejSpanel

Description

@OndrejSpanel

Compiler version

3.3.7, 3.7.4, 3.8.0-RC3, 3.nightly

Minimized code

//> using scala 3.8.0-RC3
trait A
trait B extends A {
  def b: Boolean
}

def f() = {
  val s = Seq[A]()
  for (case x: B <- s if x.b) yield x
}

Output

[error] .\Main.scala:10:13
[error] Found:    B => B
[error] Required: A => B
[error]   for (case x: B <- s if x.b) yield x // this gives an error: Found B => B, Required A => B
[error]             ^^^^^^^^^^^^^^^^^^^^^^^^^

Expectation

The code should compile. It compiles when closing x: B in parentheses as case (x: B). See also https://users.scala-lang.org/t/desugaring-of-for-with-pattern-match-and-if-guard/12147/2?u=ondrejspanel

Metadata

Metadata

Assignees

Labels

area:desugarDesugaring happens after parsing but before typing, see desugar.scalaarea:parseritype:bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions