summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2012-11-01 12:08:11 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2012-11-01 12:08:11 -0700
commit59149579aec4b3d26a4cb849d80535a36b90ad30 (patch)
tree89e66e34d5420edeb480a382e777dd9b78c317a0 /src/compiler/scala/tools/nsc
parentb7d78d2d6e1d970e7ef2c02a3ad42b4356672971 (diff)
parentc3e2a81b38133f2b997e56ccd85d9bea38896a6b (diff)
downloadscala-59149579aec4b3d26a4cb849d80535a36b90ad30.tar.gz
scala-59149579aec4b3d26a4cb849d80535a36b90ad30.tar.bz2
scala-59149579aec4b3d26a4cb849d80535a36b90ad30.zip
Merge pull request #1526 from paulp/value-classes/6534-equals
New take on SI-6534, value classes.
Diffstat (limited to 'src/compiler/scala/tools/nsc')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala19
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.