scala icon indicating copy to clipboard operation
scala copied to clipboard

False positive with strict-unsealed-patmat and Java enum (2.11)

Open durban opened this issue 8 years ago • 0 comments

If I have a Java enum like this:

package com.example;

public enum MyEnum {
  FOO,
  BAR,
  BAZ,
}

And I match on it from Scala like this:

package com.example

object Foo {
  
  def foo(e: MyEnum): Int = e match {
    case MyEnum.FOO => 1
    case MyEnum.BAR => 2
    case MyEnum.BAZ => 3
  }
}

I get a warning:

[warn] .../Foo.scala:5: match may not be exhaustive.
[warn] It would fail on the following input: (x: com.example.MyEnum forSome x not in (BAR, BAZ, FOO))
[warn]   def foo(e: MyEnum): Int = e match {
[warn]                             ^

Build options:

scalaVersion := "2.11.11-bin-typelevel-4"
scalaOrganization := "org.typelevel"
scalacOptions += "-Xlint:strict-unsealed-patmat"

Note, that I cannot reproduce the issue with version 2.12.2-bin-typelevel-4.

durban avatar May 14 '17 16:05 durban