diff options
author | Simon Ochsenreither <simon@ochsenreither.de> | 2016-01-07 19:07:45 +0100 |
---|---|---|
committer | Simon Ochsenreither <simon@ochsenreither.de> | 2016-01-14 00:01:40 +0100 |
commit | 11783c3c2a6692cfbb41b14734504b86101ed955 (patch) | |
tree | 094d7e5b3155f2325e8d6d290772433b1382228e /src/compiler/scala/tools/nsc/javac | |
parent | fb22e2b0a73605d654c153e02d454e5cec21f355 (diff) | |
download | scala-11783c3c2a6692cfbb41b14734504b86101ed955.tar.gz scala-11783c3c2a6692cfbb41b14734504b86101ed955.tar.bz2 scala-11783c3c2a6692cfbb41b14734504b86101ed955.zip |
SI-8700 Exhaustiveness warning for enums from Java source
Until now, the warning was only emitted for enums from Java class files.
This commit fixes it by
- aligning the flags set in JavaParsers with the flags set in
ClassfileParser (which are required by the pattern matcher to
even consider checking exhaustiveness)
- adding the enum members as childs to the class holding the enum
as done in ClassfileParser so that the pattern matcher sees the enum
members when looking for the sealed children of a type
Diffstat (limited to 'src/compiler/scala/tools/nsc/javac')
-rw-r--r-- | src/compiler/scala/tools/nsc/javac/JavaParsers.scala | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index eb25eb6e06..7224523a41 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -800,16 +800,10 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { val superclazz = AppliedTypeTree(javaLangDot(tpnme.Enum), List(enumType)) val finalFlag = if (enumIsFinal) Flags.FINAL else 0l - val abstractFlag = { - // javac adds `ACC_ABSTRACT` to enum classes with deferred members - val hasAbstractMember = body exists { - case d: DefDef => d.mods.isDeferred - case _ => false - } - if (hasAbstractMember) Flags.ABSTRACT else 0l - } addCompanionObject(consts ::: statics ::: predefs, atPos(pos) { - ClassDef(mods | Flags.JAVA_ENUM | finalFlag | abstractFlag, name, List(), + // Marking the enum class SEALED | ABSTRACT enables exhaustiveness checking. See also ClassfileParser. + // This is a bit of a hack and requires excluding the ABSTRACT flag in the backend, see method javaClassfileFlags. + ClassDef(mods | Flags.JAVA_ENUM | Flags.SEALED | Flags.ABSTRACT | finalFlag, name, List(), makeTemplate(superclazz :: interfaces, body)) }) } |