summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-10-30 07:43:03 -0700
committerPaul Phillips <paulp@improving.org>2012-10-30 07:56:05 -0700
commitc3e2a81b38133f2b997e56ccd85d9bea38896a6b (patch)
treec169f7db6e60e4fd76cd7739472166b07625d83f
parenta7276d5976f57d4f182a55f92693de97acf1de64 (diff)
downloadscala-c3e2a81b38133f2b997e56ccd85d9bea38896a6b.tar.gz
scala-c3e2a81b38133f2b997e56ccd85d9bea38896a6b.tar.bz2
scala-c3e2a81b38133f2b997e56ccd85d9bea38896a6b.zip
Modification to SI-6534 patch.
Only exclude hashCode and equals from being overridden in value classes, not other synthetics which may turn up such as case class methods.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala20
-rw-r--r--test/files/neg/t6534.check5
-rw-r--r--test/files/neg/t6534.scala3
3 files changed, 18 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
index 0fda025972..903b5904d3 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
@@ -310,17 +310,19 @@ trait SyntheticMethods extends ast.TreeDSL {
* 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")
+ 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")
+ }
}
-
- impl()
+ true
+ }
}
- else
- for ((m, impl) <- methods ; if !hasOverridingImplementation(m)) yield impl()
+ }
+ for ((m, impl) <- methods ; if shouldGenerate(m)) yield impl()
}
def extras = (
if (needsReadResolve) {
diff --git a/test/files/neg/t6534.check b/test/files/neg/t6534.check
index bd7dc4b71c..52e70cfa8a 100644
--- a/test/files/neg/t6534.check
+++ b/test/files/neg/t6534.check
@@ -10,5 +10,8 @@ class Bippy3(val x: Int) extends AnyVal { override def equals(x: Any) = false }
t6534.scala:7: error: redefinition of hashCode method. See SIP-15, criterion 4. is not allowed in value class
class Bippy4(val x: Int) extends AnyVal { override def hashCode = -1 } // error
^
+t6534.scala:9: error: redefinition of equals method. See SIP-15, criterion 4. is not allowed in value class
+case class Bippy6(val x: Int) extends AnyVal { override def productPrefix = "Dingo" ; override def equals(x: Any) = false } // error
+ ^
two warnings found
-two errors found
+three errors found
diff --git a/test/files/neg/t6534.scala b/test/files/neg/t6534.scala
index a193179399..de588b69a7 100644
--- a/test/files/neg/t6534.scala
+++ b/test/files/neg/t6534.scala
@@ -5,3 +5,6 @@ class Bippy1(val x: Int) extends AnyVal with Foo { } // warn
class Bippy2(val x: Int) extends AnyVal with Ding { } // warn
class Bippy3(val x: Int) extends AnyVal { override def equals(x: Any) = false } // error
class Bippy4(val x: Int) extends AnyVal { override def hashCode = -1 } // error
+case class Bippy5(val x: Int) extends AnyVal { override def productPrefix = "Dingo" } // nothing
+case class Bippy6(val x: Int) extends AnyVal { override def productPrefix = "Dingo" ; override def equals(x: Any) = false } // error
+