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

False Positive: PartialFunctionInsteadOfMatch when using yield #239

Open
bjchambers opened this issue Aug 17, 2019 · 2 comments
Open

False Positive: PartialFunctionInsteadOfMatch when using yield #239

bjchambers opened this issue Aug 17, 2019 · 2 comments

Comments

@bjchambers
Copy link

    implicit val ec: ExecutionContext = ExecutionContext.global
    val foo = for {
      x <- Future[Any](5)
    } yield x match {
      case i: Int    =>
      case s: String =>
    }

Produces the error:

[error] Match instead of partial function
          A map match can be replaced with a partial function for greater readability: scala.concurrent.Future.apply[Any](5)(ec).map[Unit](((x: Any) => x match {
  case (i @ (_: Int)) => ()
  case (s @ (_: String)) => ()
}))

However, there is no way to do that, since the map is implicitly part of the yield.

@mwz
Copy link
Contributor

mwz commented Feb 7, 2020

I'm seeing the same warning when using the better-monadic-for compiler plugin, e.g.:

val ab = for {
  (a, b) <- Some(("a", "b"))
} yield a + b

Results in the following:

Match instead of partial function
          A map match can be replaced with a partial function for greater readability: scala.Some.apply[(String, String)](scala.Tuple2.apply[String, String]("a", "b")).map[String](((x$6: (String, String)) => x$6 match {
  case (_1: String, _2: String)(String, String)((a @ _), (b @ _)) => a.+(b)
}))

Match instead of partial function
          (a, b) <- Some(("a", "b"))

Any pointers on how this can be fixed?

@mr-git
Copy link

mr-git commented Aug 11, 2020

for now, one can disable the check by amending build.sbt with:

    ThisBuild / scapegoatDisabledInspections := Seq("PartialFunctionInsteadOfMatch")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants