diff options
author | Paul Phillips <paulp@improving.org> | 2012-10-24 13:23:54 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-10-24 13:52:41 -0700 |
commit | a7276d5976f57d4f182a55f92693de97acf1de64 (patch) | |
tree | d8aef3889d0ae87cc4ea5ae75ed5addd8b34ea86 /src/compiler | |
parent | 2c554249fd8e99286134b217027b6e3cb2c92d77 (diff) | |
download | scala-a7276d5976f57d4f182a55f92693de97acf1de64.tar.gz scala-a7276d5976f57d4f182a55f92693de97acf1de64.tar.bz2 scala-a7276d5976f57d4f182a55f92693de97acf1de64.zip |
New take on SI-6534, value classes.
Don't prohibit equals and hashCode in universal traits;
instead, always override them in value classes.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index cc3d980cf1..0fda025972 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -306,7 +306,22 @@ 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 = { + if (clazz.isDerivedValueClass) + for ((m, impl) <- methods) yield { + 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") + } + + impl() + } + else + for ((m, impl) <- methods ; if !hasOverridingImplementation(m)) yield impl() + } def extras = ( if (needsReadResolve) { // Aha, I finally decoded the original comment. |