diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala | 26 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 8 | ||||
-rw-r--r-- | test/files/neg/caseinherit.check | 6 | ||||
-rw-r--r-- | test/files/neg/caseinherit.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t0816.check | 4 | ||||
-rw-r--r-- | test/files/neg/t0816.scala (renamed from test/files/pos/t0816.scala) | 0 | ||||
-rw-r--r-- | test/files/neg/t425.check | 4 | ||||
-rw-r--r-- | test/files/neg/t425.scala (renamed from test/files/pos/t425.scala) | 0 |
8 files changed, 15 insertions, 34 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index 2da8992320..63456849cd 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -35,22 +35,6 @@ trait SyntheticMethods extends ast.TreeDSL { import global._ // the global environment import definitions._ // standard classes and methods - /** In general case classes/objects are not given synthetic equals methods if some - * non-AnyRef implementation is inherited. However if you let a case object inherit - * an implementation from a case class, it creates an asymmetric equals with all the - * associated badness: see ticket #883. So if it sees such a thing this has happened - * (by virtue of the symbol being in createdMethodSymbols) it re-overrides it with - * reference equality. - * - * TODO: remove once (deprecated) case class inheritance is dropped form nsc. - */ - private val createdMethodSymbols = new mutable.HashSet[Symbol] - - /** Clear the cache of createdMethodSymbols. */ - def resetSynthetics() { - createdMethodSymbols.clear() - } - /** Add the synthetic methods to case classes. Note that a lot of the * complexity herein is a consequence of case classes inheriting from * case classes, which has been deprecated as of Sep 11 2009. So when @@ -64,7 +48,7 @@ trait SyntheticMethods extends ast.TreeDSL { def hasOverridingImplementation(meth: Symbol): Boolean = { val sym = clazz.info nonPrivateMember meth.name def isOverride(s: Symbol) = { - s != meth && !s.isDeferred && !s.isSynthetic && !createdMethodSymbols(s) && + s != meth && !s.isDeferred && !s.isSynthetic && (clazz.thisType.memberType(s) matches clazz.thisType.memberType(meth)) } sym.alternatives exists isOverride @@ -75,7 +59,6 @@ trait SyntheticMethods extends ast.TreeDSL { def newSyntheticMethod(name: Name, flags: Int, tpeCons: Symbol => Type) = { val method = clazz.newMethod(clazz.pos.focus, name.toTermName) setFlag flags - createdMethodSymbols += method method setInfo tpeCons(method) clazz.info.decls.enter(method) } @@ -286,13 +269,6 @@ trait SyntheticMethods extends ast.TreeDSL { ) } - if (clazz.isModuleClass) { - // if there's a synthetic method in a parent case class, override its equality - // with eq (see #883) - val otherEquals = clazz.info.nonPrivateMember(Object_equals.name) - if (otherEquals.owner != clazz && createdMethodSymbols(otherEquals)) ts += equalsModuleMethod - } - val methods = (if (clazz.isModuleClass) objectMethods else classMethods) ++ everywhereMethods for ((m, impl) <- methods ; if !hasOverridingImplementation(m)) ts += impl() diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 97e07d9f3e..1988bc887f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -50,7 +50,6 @@ trait Typers extends Modes { resetNamer() resetImplicits() transformed.clear() - resetSynthetics() } object UnTyper extends Traverser { @@ -1076,10 +1075,9 @@ trait Typers extends Modes { private def validateNoCaseAncestor(clazz: Symbol) = { if (!phase.erasedTypes) { for (ancestor <- clazz.ancestors find (_.isCase)) { - unit.deprecationWarning(clazz.pos, ( - "case class `%s' has case ancestor `%s'. Case-to-case inheritance has potentially "+ - "dangerous bugs which are unlikely to be fixed. You are strongly encouraged to "+ - "instead use extractors to pattern match on non-leaf nodes." + unit.error(clazz.pos, ( + "case class `%s' has case ancestor `%s'. Case-to-case inheritance is prohibited."+ + " To overcome this limitation use extractors to pattern match on non-leaf nodes." ).format(clazz, ancestor)) } } diff --git a/test/files/neg/caseinherit.check b/test/files/neg/caseinherit.check index 5630da2a3e..c185c82f70 100644 --- a/test/files/neg/caseinherit.check +++ b/test/files/neg/caseinherit.check @@ -1,10 +1,10 @@ -caseinherit.scala:2: error: case class `class B' has case ancestor `class A'. Case-to-case inheritance has potentially dangerous bugs which are unlikely to be fixed. You are strongly encouraged to instead use extractors to pattern match on non-leaf nodes. +caseinherit.scala:2: error: case class `class B' has case ancestor `class A'. Case-to-case inheritance is prohibited. To overcome this limitation use extractors to pattern match on non-leaf nodes. case class B(y: Int) extends A(y) ^ -caseinherit.scala:3: error: case class `object Bippy' has case ancestor `class A'. Case-to-case inheritance has potentially dangerous bugs which are unlikely to be fixed. You are strongly encouraged to instead use extractors to pattern match on non-leaf nodes. +caseinherit.scala:3: error: case class `object Bippy' has case ancestor `class A'. Case-to-case inheritance is prohibited. To overcome this limitation use extractors to pattern match on non-leaf nodes. case object Bippy extends A(55) ^ -caseinherit.scala:6: error: case class `class Dingus' has case ancestor `class A'. Case-to-case inheritance has potentially dangerous bugs which are unlikely to be fixed. You are strongly encouraged to instead use extractors to pattern match on non-leaf nodes. +caseinherit.scala:6: error: case class `class Dingus' has case ancestor `class A'. Case-to-case inheritance is prohibited. To overcome this limitation use extractors to pattern match on non-leaf nodes. case class Dingus(y: Int) extends Innocent ^ three errors found diff --git a/test/files/neg/caseinherit.flags b/test/files/neg/caseinherit.flags deleted file mode 100644 index e8fb65d50c..0000000000 --- a/test/files/neg/caseinherit.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/t0816.check b/test/files/neg/t0816.check new file mode 100644 index 0000000000..ff6489be99 --- /dev/null +++ b/test/files/neg/t0816.check @@ -0,0 +1,4 @@ +t0816.scala:5: error: case class `class Ctest' has case ancestor `class Btest'. Case-to-case inheritance is prohibited. To overcome this limitation use extractors to pattern match on non-leaf nodes. +case class Ctest(override val data: String) extends Btest(data, true) + ^ +one error found diff --git a/test/files/pos/t0816.scala b/test/files/neg/t0816.scala index 0128a0ad72..0128a0ad72 100644 --- a/test/files/pos/t0816.scala +++ b/test/files/neg/t0816.scala diff --git a/test/files/neg/t425.check b/test/files/neg/t425.check new file mode 100644 index 0000000000..671c128753 --- /dev/null +++ b/test/files/neg/t425.check @@ -0,0 +1,4 @@ +t425.scala:3: error: case class `class B' has case ancestor `class A'. Case-to-case inheritance is prohibited. To overcome this limitation use extractors to pattern match on non-leaf nodes. + case class B(override val x: Int, y: Double) extends A(x) + ^ +one error found diff --git a/test/files/pos/t425.scala b/test/files/neg/t425.scala index e50c50ac35..e50c50ac35 100644 --- a/test/files/pos/t425.scala +++ b/test/files/neg/t425.scala |