Skip to content

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

@bishabosha

Description

@bishabosha

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:pattern-matchingarea:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions