Skip to content

Commit

Permalink
Only add FunctionN parent when class has simple constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdziuban committed Apr 26, 2019
1 parent b9f29e8 commit 7da579d
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ abstract class AnnotationPlugin(override val global: Global) extends Plugin {
case _ => false
}

private def getConstructor(clazz: ClassDef): Option[DefDef] =
clazz.impl.collect {
case d @ DefDef(_, nme.CONSTRUCTOR, _, _, _, _) => d
}.headOption

// A simple constructor is one with only one parameter group and no implicit parameters
private def hasSimpleConstructor(clazz: ClassDef): Boolean =
getConstructor(clazz) match {
case Some(DefDef(_, _, _, ps :: Nil, _, _))
if !ps.exists(_.mods.hasFlag(Flag.IMPLICIT)) =>
true
case _ => false
}

/** generates a zero-functionality companion for a class */
private def genCompanion(clazz: ClassDef): ModuleDef = {
val mods =
Expand All @@ -198,6 +212,7 @@ abstract class AnnotationPlugin(override val global: Global) extends Plugin {
def sup =
if (isCase &&
clazz.tparams.isEmpty &&
hasSimpleConstructor(clazz) &&
addSuperFunction(clazz) &&
accessors.size <= 22) {
AppliedTypeTree(
Expand Down

0 comments on commit 7da579d

Please sign in to comment.