aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-11-16 13:02:49 +0100
committerMartin Odersky <odersky@gmail.com>2015-12-14 14:30:10 +0100
commit21948a58c0c47363addf0dd87f1527e9b0aec76f (patch)
treef31875062117d58977fdd1d0432722f89c56bd9e
parent0a19b0b94393e47865f21f714e82676a67ab2e4d (diff)
downloaddotty-21948a58c0c47363addf0dd87f1527e9b0aec76f.tar.gz
dotty-21948a58c0c47363addf0dd87f1527e9b0aec76f.tar.bz2
dotty-21948a58c0c47363addf0dd87f1527e9b0aec76f.zip
Generalize overriding checking from isDefined
Generalize overriding checking from isDefined to all methods added by desugar to a case class. None of these methods has an override so we need to add one in case they do override another method (previously we would flag this as an error).
-rw-r--r--src/dotty/tools/dotc/ast/Desugar.scala7
-rw-r--r--src/dotty/tools/dotc/core/NameOps.scala1
-rw-r--r--src/dotty/tools/dotc/typer/RefChecks.scala2
3 files changed, 9 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala
index 72dd8cb4c..12f3e4406 100644
--- a/src/dotty/tools/dotc/ast/Desugar.scala
+++ b/src/dotty/tools/dotc/ast/Desugar.scala
@@ -21,6 +21,13 @@ object desugar {
/** Info of a variable in a pattern: The named tree and its type */
private type VarInfo = (NameTree, Tree)
+ /** Names of methods that are added unconditionally to case classes */
+ def isDesugaredCaseClassMethodName(name: Name)(implicit ctx: Context) =
+ name == nme.isDefined ||
+ name == nme.copy ||
+ name == nme.productArity ||
+ name.isSelectorName
+
// ----- DerivedTypeTrees -----------------------------------
class SetterParamTree extends DerivedTypeTree {
diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala
index 7dbd492b4..6c1930c9f 100644
--- a/src/dotty/tools/dotc/core/NameOps.scala
+++ b/src/dotty/tools/dotc/core/NameOps.scala
@@ -81,6 +81,7 @@ object NameOps {
def isScala2LocalSuffix = name.endsWith(" ")
def isModuleVarName(name: Name): Boolean =
name.stripAnonNumberSuffix endsWith MODULE_VAR_SUFFIX
+ def isSelectorName = name.startsWith(" ") && name.tail.forall(_.isDigit)
/** Is name a variable name? */
def isVariableName: Boolean = name.length > 0 && {
diff --git a/src/dotty/tools/dotc/typer/RefChecks.scala b/src/dotty/tools/dotc/typer/RefChecks.scala
index 416a2cb92..44d5ee576 100644
--- a/src/dotty/tools/dotc/typer/RefChecks.scala
+++ b/src/dotty/tools/dotc/typer/RefChecks.scala
@@ -288,7 +288,7 @@ object RefChecks {
!member.isAnyOverride) {
// (*) Exclusion for default getters, fixes SI-5178. We cannot assign the Override flag to
// the default getter: one default getter might sometimes override, sometimes not. Example in comment on ticket.
- if (member.name == nme.isDefined && member.is(Synthetic)) // isDefined methods are added automatially, can't have an override preset.
+ if (member.is(Synthetic) && desugar.isDesugaredCaseClassMethodName(member.name)) // such names are added automatically, can't have an override preset.
member.setFlag(Override)
else if (member.owner != clazz && other.owner != clazz && !(other.owner derivesFrom member.owner))
emitOverrideError(