Skip to content

Given patterns are never exhaustive, causing withFilter desugaring #12170

Closed
@oleg-py

Description

@oleg-py

Compiler version

3.0.0-RC2

Minimized code

import scala.compiletime.error

object BadFilters {
  inline def withFilter(f: Int => Boolean): BadFilters.type = error("Unexpected withFilter call")
  def foreach(f: Int => Unit): Unit = f(42)
}

@main def works = 
  for {
    x: Int <- BadFilters
  } println(x)

@main def breaks =
  for {
    given Int <- BadFilters
  } println(summon[Int])

Output

Fails to compile breaks with Unexpected withFilter call

Expectation

Compiles and prints:

42
42

The pattern x: Int is considered exhaustive, causing withFilter to not be emitted in works, while the pattern given Int isn't, so withFilter is emitted and breaks breaks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions