@@ -34,17 +34,14 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
3434 // Because it adds additional parameters to some constructors
3535
3636 def transformInfo (tp : Type , sym : Symbol )(implicit ctx : Context ): Type =
37- if (sym.isConstructor && (
38- sym == defn.JavaEnumClass .primaryConstructor ||
39- derivesFromJavaEnum(sym.owner)))
40- addConstrParams(sym.info)
37+ if (sym.isConstructor && derivesFromJEnum(sym.owner)) addConstrParams(sym.info)
4138 else tp
4239
4340 /** Is `sym` a Scala enum class that derives (directly) from `java.lang.Enum`?
4441 */
45- private def derivesFromJavaEnum (sym : Symbol )(implicit ctx : Context ) =
42+ private def derivesFromJEnum (sym : Symbol )(implicit ctx : Context ) =
4643 sym.is(Enum , butNot = Case ) &&
47- sym.info.parents.exists(p => p.typeSymbol == defn.JavaEnumClass )
44+ sym.info.parents.exists(p => p.typeSymbol == defn.JEnumClass )
4845
4946 /** Add constructor parameters `$name: String` and `$ordinal: Int` to the end of
5047 * the last parameter list of (method- or poly-) type `tp`.
@@ -100,10 +97,10 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
10097 */
10198 override def transformDefDef (tree : DefDef )(implicit ctx : Context ): DefDef = {
10299 val sym = tree.symbol
103- if (sym.isConstructor && derivesFromJavaEnum (sym.owner))
100+ if (sym.isConstructor && derivesFromJEnum (sym.owner))
104101 cpy.DefDef (tree)(
105102 vparamss = tree.vparamss.init :+ (tree.vparamss.last ++ addedParams(sym, Param )))
106- else if (sym.name == nme.DOLLAR_NEW && derivesFromJavaEnum (sym.owner.linkedClass)) {
103+ else if (sym.name == nme.DOLLAR_NEW && derivesFromJEnum (sym.owner.linkedClass)) {
107104 val Block ((tdef @ TypeDef (tpnme.ANON_CLASS , templ : Template )) :: Nil , call) = tree.rhs
108105 val args = tree.vparamss.last.takeRight(2 ).map(param => ref(param.symbol)).reverse
109106 val templ1 = cpy.Template (templ)(
@@ -115,7 +112,8 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
115112 }
116113
117114 /** 1. If this is an enum class, add $name and $ordinal parameters to its
118- * parameter accessors and pass them on to the java.lang.Enum constructor.
115+ * parameter accessors and pass them on to the java.lang.Enum constructor,
116+ * replacing the dummy arguments that were passed before.
119117 *
120118 * 2. If this is an anonymous class that implement a value enum case,
121119 * pass $name and $ordinal parameters to the enum superclass. The class
@@ -136,15 +134,20 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
136134 */
137135 override def transformTemplate (templ : Template )(implicit ctx : Context ): Template = {
138136 val cls = templ.symbol.owner
139- if (derivesFromJavaEnum (cls)) {
137+ if (derivesFromJEnum (cls)) {
140138 val (params, rest) = decomposeTemplateBody(templ.body)
141139 val addedDefs = addedParams(cls, ParamAccessor )
142140 val addedSyms = addedDefs.map(_.symbol.entered)
141+ val parents1 = templ.parents.map {
142+ case app @ Apply (fn, _) if fn.symbol.owner == defn.JEnumClass =>
143+ cpy.Apply (app)(fn, addedSyms.map(ref))
144+ case p => p
145+ }
143146 cpy.Template (templ)(
144- parents = addEnumConstrArgs(defn. JavaEnumClass , templ.parents, addedSyms.map(ref)) ,
147+ parents = parents1 ,
145148 body = params ++ addedDefs ++ rest)
146149 }
147- else if (cls.isAnonymousClass && cls.owner.is(EnumCase ) && derivesFromJavaEnum (cls.owner.owner.linkedClass)) {
150+ else if (cls.isAnonymousClass && cls.owner.is(EnumCase ) && derivesFromJEnum (cls.owner.owner.linkedClass)) {
148151 def rhsOf (name : TermName ) =
149152 templ.body.collect {
150153 case mdef : DefDef if mdef.name == name => mdef.rhs
0 commit comments