diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index 001acc7a80..6afc823376 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -326,7 +326,24 @@ trait SyntheticMethods extends ast.TreeDSL { else Nil ) - def impls = for ((m, impl) <- methods ; if !hasOverridingImplementation(m)) yield impl() + /** Always generate overrides for equals and hashCode in value classes, + * so they can appear in universal traits without breaking value semantics. + */ + def impls = { + def shouldGenerate(m: Symbol) = { + !hasOverridingImplementation(m) || { + clazz.isDerivedValueClass && (m == Any_hashCode || m == Any_equals) && { + if (settings.lint.value) { + (clazz.info nonPrivateMember m.name) filter (m => (m.owner != AnyClass) && (m.owner != clazz) && !m.isDeferred) andAlso { m => + currentUnit.warning(clazz.pos, s"Implementation of ${m.name} inherited from ${m.owner} overridden in $clazz to enforce value class semantics") + } + } + true + } + } + } + for ((m, impl) <- methods ; if shouldGenerate(m)) yield impl() + } def extras = ( if (needsReadResolve) { // Aha, I finally decoded the original comment. |