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

Exhaustiveness check for Java enums doesn't work when scalac sees the enum's Java source #8700

Closed
scabug opened this issue Jul 1, 2014 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jul 1, 2014

To reproduce, create two source files:

// Foo.java
public enum Foo {
    A,
    B
}
// Bar.scala
object Bar {
    def baz(foo: Foo) = foo match {
        case Foo.A => 1
    }
}

and then try compiling Bar.scala while passing Foo.java to scalac (without compiling it first). No warning will be printed, even though the pattern match isn't exhaustive.

$ scalac Foo.java Bar.scala

If, however, the enum is compiled first and then excluded from scalac run, the warning is printed as expected:

$ javac Foo.java 
$ scalac Bar.scala 
Bar.scala:2: warning: match may not be exhaustive.
It would fail on the following input: B
    def baz(foo: Foo) = foo match {
                        ^
one warning found
@scabug
Copy link
Author

scabug commented Jul 1, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8700?orig=1
Reporter: Alexey Ermakov (technocoreai)
Affected Versions: 2.11.0
See #5333

@scabug
Copy link
Author

scabug commented Jul 4, 2014

@retronym said:
Thanks for the report. Indeed it looks like the functionality to treat Java enums as sealed was added only when reading them from class files.

See also #5333, a bug of the same nature.

@scabug
Copy link
Author

scabug commented Jan 7, 2016

@soc said (edited on Jan 8, 2016 2:26:57 PM UTC):
Ok, upon further investigation of this issue:

  • after adding SEALED and ABSTRACT flags to enums in JavaParsers, and
  • ignoring checkNoConflict(FINAL, SEALED) in Namers for isJavaEnum,

we get to the pattern matcher, which tries to find

  • the sealed children of the type in question (MatchAnalysis) using sealedDescendants
  • sealedDescendants uses children, but children is only populated in ClassfileParser (addChild), but not in JavaParsers

@scabug
Copy link
Author

scabug commented Jan 14, 2016

@lrytz said:
scala/scala#4898

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

2 participants