Skip to content
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

under future, refutable patterns in "for" do not suggest to use "case" #18622

Open
bishabosha opened this issue Sep 29, 2023 · 0 comments
Open
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@bishabosha
Copy link
Member

bishabosha commented Sep 29, 2023

under -source:future, a refutable pattern in a for comprehension only produces the standard "match may not be exhaustive" error.

Compiler version

3.3.1

Minimized code

import scala.language.future

case class BoxWithFilter[T](t: T):
  def map[U](f: T => U): BoxWithFilter[U] = ???
  def flatMap[U](f: T => BoxWithFilter[U]): BoxWithFilter[U] = ???
  def withFilter(b: T => Boolean): BoxWithFilter[T] = ???

def foo: BoxWithFilter[Int] = for x :: _ <- BoxWithFilter(List(23)) yield x

Output

[warn] ./pattern-bindings.scala:8:35
[warn] match may not be exhaustive.
[warn] 
[warn] It would fail on pattern case: Nil
[warn] def foo: BoxWithFilter[Int] = for x :: _ <- BoxWithFilter(List(23)) yield x
[warn]                                   ^

Expectation

It would be good to remind the user that they can use case in front of the pattern, which will introduce the call to withFilter

@bishabosha bishabosha added itype:enhancement area:reporting Error reporting including formatting, implicit suggestions, etc area:pattern-matching labels Sep 29, 2023
@bishabosha bishabosha added the better-errors Issues concerned with improving confusing/unhelpful diagnostic messages label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

No branches or pull requests

1 participant