Skip to content

Given patterns are never exhaustive, causing withFilter desugaring #12170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oleg-py opened this issue Apr 21, 2021 · 0 comments · Fixed by #12184
Closed

Given patterns are never exhaustive, causing withFilter desugaring #12170

oleg-py opened this issue Apr 21, 2021 · 0 comments · Fixed by #12184
Milestone

Comments

@oleg-py
Copy link

oleg-py commented Apr 21, 2021

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.

@oleg-py oleg-py changed the title Given patterns are never exhaustive Given patterns are never exhaustive, causing withFilter desugaring Apr 21, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Apr 22, 2021
These are considered irrefutable, just like normal bindings.

Fixes scala#12170
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants