Skip to content

Commit 258775e

Browse files
committed
Merge pull request #519 from smarter/fix/isSourceMethod
Fix isSourceMethod
2 parents a1790eb + 839e47c commit 258775e

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

src/dotty/tools/dotc/ast/CheckTrees.scala.disabled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ object CheckTrees {
131131
check(guard.tpe.derivesFrom(defn.BooleanClass))
132132
case Return(expr, from) =>
133133
check(expr.isValue); check(from.isTerm)
134-
check(from.tpe.termSymbol.isSourceMethod)
134+
check(from.tpe.termSymbol.isRealMethod)
135135
case Try(block, handler, finalizer) =>
136136
check(block.isTerm)
137137
check(finalizer.isTerm)

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,16 @@ object SymDenotations {
478478
}
479479
}
480480

481-
/** Is this a user defined "def" method? Excluded are accessors and anonymous functions. */
482-
final def isSourceMethod(implicit ctx: Context) =
483-
this.is(Method, butNot = AccessorOrLabel) && !isAnonymousFunction
481+
/** Is this a "real" method? A real method is a method which is:
482+
* - not an accessor
483+
* - not a label
484+
* - not an anonymous function
485+
* - not a companion method
486+
*/
487+
final def isRealMethod(implicit ctx: Context) =
488+
this.is(Method, butNot = AccessorOrLabel) &&
489+
!isAnonymousFunction &&
490+
!isCompanionMethod
484491

485492
/** Is this a setter? */
486493
final def isGetter(implicit ctx: Context) =

src/dotty/tools/dotc/transform/ValueClasses.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ object ValueClasses {
2020
}
2121

2222
def isMethodWithExtension(d: SymDenotation)(implicit ctx: Context) =
23-
d.isSourceMethod &&
23+
d.isRealMethod &&
2424
isDerivedValueClass(d.owner) &&
2525
!d.isConstructor &&
2626
!d.is(SuperAccessor) &&
27-
!d.is(Macro) &&
28-
!d.isCompanionMethod
27+
!d.is(Macro)
2928

3029
/** The member that of a derived value class that unboxes it. */
3130
def valueClassUnbox(d: ClassDenotation)(implicit ctx: Context): Symbol =

src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ trait Checking {
312312
def doubleDefError(decl: Symbol, other: Symbol): Unit = {
313313
def ofType = if (decl.isType) "" else d": ${other.info}"
314314
def explanation =
315-
if (!decl.isSourceMethod) ""
315+
if (!decl.isRealMethod) ""
316316
else "\n (both definitions have the same erased type signature)"
317317
ctx.error(d"$decl is already defined as $other$ofType$explanation", decl.pos)
318318
}

src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ object RefChecks {
297297
"(this rule is designed to prevent ``accidental overrides'')")
298298
} else if (other.isStable && !member.isStable) { // (1.4)
299299
overrideError("needs to be a stable, immutable value")
300-
} else if (member.is(Lazy) && !other.isSourceMethod && !other.is(Deferred | Lazy)) {
300+
} else if (member.is(Lazy) && !other.isRealMethod && !other.is(Deferred | Lazy)) {
301301
overrideError("cannot override a concrete non-lazy value")
302-
} else if (other.is(Lazy, butNot = Deferred) && !other.isSourceMethod && !member.is(Lazy)) {
302+
} else if (other.is(Lazy, butNot = Deferred) && !other.isRealMethod && !member.is(Lazy)) {
303303
overrideError("must be declared lazy to override a concrete lazy value")
304304
} else if (other.is(Deferred) && member.is(Macro) && member.extendedOverriddenSymbols.forall(_.is(Deferred))) { // (1.9)
305305
overrideError("cannot be used here - term macros cannot override abstract methods")
@@ -1132,7 +1132,7 @@ class RefChecks extends MiniPhase { thisTransformer =>
11321132
}
11331133
11341134
val doTransform =
1135-
sym.isSourceMethod &&
1135+
sym.isRealMethod &&
11361136
sym.isCase &&
11371137
sym.name == nme.apply &&
11381138
isClassTypeAccessible(tree)

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
708708
ctx.error("return outside method definition", tree.pos)
709709
(EmptyTree, WildcardType)
710710
}
711-
else if (owner != cx.outer.owner && owner.isSourceMethod) {
711+
else if (owner != cx.outer.owner && owner.isRealMethod) {
712712
if (owner.isCompleted) {
713713
val from = Ident(TermRef(NoPrefix, owner.asTerm))
714714
val proto = returnProto(owner, cx.scope)

0 commit comments

Comments
 (0)