From 37851350754403323b26c0c32417cbecc0c44584 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sat, 9 May 2015 21:33:19 +0200 Subject: rename isSourceMethod to isRealMethod, the previous name was inaccurate --- src/dotty/tools/dotc/ast/CheckTrees.scala.disabled | 2 +- src/dotty/tools/dotc/core/SymDenotations.scala | 8 ++++++-- src/dotty/tools/dotc/transform/ValueClasses.scala | 2 +- src/dotty/tools/dotc/typer/Checking.scala | 2 +- src/dotty/tools/dotc/typer/RefChecks.scala | 6 +++--- src/dotty/tools/dotc/typer/Typer.scala | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/dotty/tools/dotc/ast/CheckTrees.scala.disabled b/src/dotty/tools/dotc/ast/CheckTrees.scala.disabled index 254f002c1..255619f35 100644 --- a/src/dotty/tools/dotc/ast/CheckTrees.scala.disabled +++ b/src/dotty/tools/dotc/ast/CheckTrees.scala.disabled @@ -131,7 +131,7 @@ object CheckTrees { check(guard.tpe.derivesFrom(defn.BooleanClass)) case Return(expr, from) => check(expr.isValue); check(from.isTerm) - check(from.tpe.termSymbol.isSourceMethod) + check(from.tpe.termSymbol.isRealMethod) case Try(block, handler, finalizer) => check(block.isTerm) check(finalizer.isTerm) diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index b93585324..1d3434091 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -478,8 +478,12 @@ object SymDenotations { } } - /** Is this a user defined "def" method? Excluded are accessors and anonymous functions. */ - final def isSourceMethod(implicit ctx: Context) = + /** Is this a "real" method? A real method is a method which is: + * - not an accessor + * - not a label + * - not an anonymous function + */ + final def isRealMethod(implicit ctx: Context) = this.is(Method, butNot = AccessorOrLabel) && !isAnonymousFunction /** Is this a setter? */ diff --git a/src/dotty/tools/dotc/transform/ValueClasses.scala b/src/dotty/tools/dotc/transform/ValueClasses.scala index f17a0e757..308eed968 100644 --- a/src/dotty/tools/dotc/transform/ValueClasses.scala +++ b/src/dotty/tools/dotc/transform/ValueClasses.scala @@ -20,7 +20,7 @@ object ValueClasses { } def isMethodWithExtension(d: SymDenotation)(implicit ctx: Context) = - d.isSourceMethod && + d.isRealMethod && isDerivedValueClass(d.owner) && !d.isConstructor && !d.is(SuperAccessor) && diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala index 148e31885..ffb74839d 100644 --- a/src/dotty/tools/dotc/typer/Checking.scala +++ b/src/dotty/tools/dotc/typer/Checking.scala @@ -312,7 +312,7 @@ trait Checking { def doubleDefError(decl: Symbol, other: Symbol): Unit = { def ofType = if (decl.isType) "" else d": ${other.info}" def explanation = - if (!decl.isSourceMethod) "" + if (!decl.isRealMethod) "" else "\n (both definitions have the same erased type signature)" ctx.error(d"$decl is already defined as $other$ofType$explanation", decl.pos) } diff --git a/src/dotty/tools/dotc/typer/RefChecks.scala b/src/dotty/tools/dotc/typer/RefChecks.scala index eeed83bb5..97d005112 100644 --- a/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/src/dotty/tools/dotc/typer/RefChecks.scala @@ -297,9 +297,9 @@ object RefChecks { "(this rule is designed to prevent ``accidental overrides'')") } else if (other.isStable && !member.isStable) { // (1.4) overrideError("needs to be a stable, immutable value") - } else if (member.is(Lazy) && !other.isSourceMethod && !other.is(Deferred | Lazy)) { + } else if (member.is(Lazy) && !other.isRealMethod && !other.is(Deferred | Lazy)) { overrideError("cannot override a concrete non-lazy value") - } else if (other.is(Lazy, butNot = Deferred) && !other.isSourceMethod && !member.is(Lazy)) { + } else if (other.is(Lazy, butNot = Deferred) && !other.isRealMethod && !member.is(Lazy)) { overrideError("must be declared lazy to override a concrete lazy value") } else if (other.is(Deferred) && member.is(Macro) && member.extendedOverriddenSymbols.forall(_.is(Deferred))) { // (1.9) overrideError("cannot be used here - term macros cannot override abstract methods") @@ -1132,7 +1132,7 @@ class RefChecks extends MiniPhase { thisTransformer => } val doTransform = - sym.isSourceMethod && + sym.isRealMethod && sym.isCase && sym.name == nme.apply && isClassTypeAccessible(tree) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 191a13ad0..566e8289a 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -708,7 +708,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit ctx.error("return outside method definition", tree.pos) (EmptyTree, WildcardType) } - else if (owner != cx.outer.owner && owner.isSourceMethod) { + else if (owner != cx.outer.owner && owner.isRealMethod) { if (owner.isCompleted) { val from = Ident(TermRef(NoPrefix, owner.asTerm)) val proto = returnProto(owner, cx.scope) -- cgit v1.2.3 From 839e47cc8a527a5777361bf750095739adb3c7eb Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sat, 9 May 2015 21:36:51 +0200 Subject: Companion methods are not real methods --- src/dotty/tools/dotc/core/SymDenotations.scala | 5 ++++- src/dotty/tools/dotc/transform/ValueClasses.scala | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 1d3434091..1ad718c29 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -482,9 +482,12 @@ object SymDenotations { * - not an accessor * - not a label * - not an anonymous function + * - not a companion method */ final def isRealMethod(implicit ctx: Context) = - this.is(Method, butNot = AccessorOrLabel) && !isAnonymousFunction + this.is(Method, butNot = AccessorOrLabel) && + !isAnonymousFunction && + !isCompanionMethod /** Is this a setter? */ final def isGetter(implicit ctx: Context) = diff --git a/src/dotty/tools/dotc/transform/ValueClasses.scala b/src/dotty/tools/dotc/transform/ValueClasses.scala index 308eed968..30802f426 100644 --- a/src/dotty/tools/dotc/transform/ValueClasses.scala +++ b/src/dotty/tools/dotc/transform/ValueClasses.scala @@ -24,8 +24,7 @@ object ValueClasses { isDerivedValueClass(d.owner) && !d.isConstructor && !d.is(SuperAccessor) && - !d.is(Macro) && - !d.isCompanionMethod + !d.is(Macro) /** The member that of a derived value class that unboxes it. */ def valueClassUnbox(d: ClassDenotation)(implicit ctx: Context): Symbol = -- cgit v1.2.3