diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2012-11-01 12:08:11 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2012-11-01 12:08:11 -0700 |
commit | 59149579aec4b3d26a4cb849d80535a36b90ad30 (patch) | |
tree | 89e66e34d5420edeb480a382e777dd9b78c317a0 /src/compiler/scala | |
parent | b7d78d2d6e1d970e7ef2c02a3ad42b4356672971 (diff) | |
parent | c3e2a81b38133f2b997e56ccd85d9bea38896a6b (diff) | |
download | scala-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')
-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. |