Skip to content

Do not generate equals method for case object #3125

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

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {

private var myValueSymbols: List[Symbol] = Nil
private var myCaseSymbols: List[Symbol] = Nil
private var myCaseModuleSymbols: List[Symbol] = Nil

private def initSymbols(implicit ctx: Context) =
if (myValueSymbols.isEmpty) {
myValueSymbols = List(defn.Any_hashCode, defn.Any_equals)
myCaseSymbols = myValueSymbols ++ List(defn.Any_toString, defn.Product_canEqual,
defn.Product_productArity, defn.Product_productPrefix, defn.Product_productElement)
myCaseModuleSymbols = myCaseSymbols.filter(_ ne defn.Any_equals)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just do myValueSymbols = defn.Any_hashCode :: (if (clazz.is(Module)) defn.Any_equals :: Nil else Nil) instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can't be done here, this is precomputing the lists for any clazz. We do not have access to the clazz in initSymbols

}

def valueSymbols(implicit ctx: Context) = { initSymbols; myValueSymbols }
def caseSymbols(implicit ctx: Context) = { initSymbols; myCaseSymbols }
def caseModuleSymbols(implicit ctx: Context) = { initSymbols; myCaseModuleSymbols }

/** The synthetic methods of the case or value class `clazz`. */
def syntheticMethods(clazz: ClassSymbol)(implicit ctx: Context): List[Tree] = {
Expand All @@ -62,7 +65,10 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
clazz.caseAccessors

val symbolsToSynthesize: List[Symbol] =
if (clazz.is(Case)) caseSymbols
if (clazz.is(Case)) {
if (clazz.is(Module)) caseModuleSymbols
else caseSymbols
}
else if (isDerivedValueClass(clazz)) valueSymbols
else Nil

Expand Down