aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Namer.scala
diff options
context:
space:
mode:
authorliu fengyun <liufengyunchina@gmail.com>2016-07-21 10:41:59 +0200
committerliu fengyun <liufengyunchina@gmail.com>2016-08-24 10:26:58 +0200
commit1a7618f32c6d8060c3a87ce633645440d500aa7a (patch)
treec61d576426280d36417e64198716c71aa9e0b6ca /src/dotty/tools/dotc/typer/Namer.scala
parent265ade02e522c89844076b5339267eac08e44c37 (diff)
downloaddotty-1a7618f32c6d8060c3a87ce633645440d500aa7a.tar.gz
dotty-1a7618f32c6d8060c3a87ce633645440d500aa7a.tar.bz2
dotty-1a7618f32c6d8060c3a87ce633645440d500aa7a.zip
implementation of exhaustivity and redundancy check
Diffstat (limited to 'src/dotty/tools/dotc/typer/Namer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index b8e75664c..3c0a45e94 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -414,6 +414,16 @@ class Namer { typer: Typer =>
case mdef: DefTree =>
val sym = enterSymbol(createSymbol(mdef))
setDocstring(sym, stat)
+
+ // add java enum constants
+ mdef match {
+ case vdef: ValDef if (isEnumConstant(vdef)) =>
+ val enumClass = sym.owner.linkedClass
+ if (!(enumClass is Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed)
+ enumClass.addAnnotation(Annotation.makeChild(sym))
+ case _ =>
+ }
+
ctx
case stats: Thicket =>
for (tree <- stats.toList) {
@@ -425,6 +435,24 @@ class Namer { typer: Typer =>
ctx
}
+ /** Determines whether this field holds an enum constant.
+ * To qualify, the following conditions must be met:
+ * - The field's class has the ENUM flag set
+ * - The field's class extends java.lang.Enum
+ * - The field has the ENUM flag set
+ * - The field is static
+ * - The field is stable
+ */
+ def isEnumConstant(vd: ValDef)(implicit ctx: Context) = {
+ // val ownerHasEnumFlag =
+ // Necessary to check because scalac puts Java's static members into the companion object
+ // while Scala's enum constants live directly in the class.
+ // We don't check for clazz.superClass == JavaEnumClass, because this causes a illegal
+ // cyclic reference error. See the commit message for details.
+ // if (ctx.compilationUnit.isJava) ctx.owner.companionClass.is(Enum) else ctx.owner.is(Enum)
+ vd.mods.is(allOf(Enum, Stable, JavaStatic, JavaDefined)) // && ownerHasEnumFlag
+ }
+
def setDocstring(sym: Symbol, tree: Tree)(implicit ctx: Context) = tree match {
case t: MemberDef => ctx.docbase.addDocstring(sym, t.rawComment)
case _ => ()