Skip to content

Commit 94716b9

Browse files
committed
SymDenotation.isEffectivelyFinal
Helper method that tests weather this particular SymDenotation cant have overrides: eg if it's defined in module class, if it is inner method, if it is method of anonymous class, etc.
1 parent 3750291 commit 94716b9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,15 @@ object Flags {
470470
/** Labeled `private` or `protected[local]` */
471471
final val PrivateOrLocal = Private | Local
472472

473+
/** Either a module or a final class */
474+
final val ModuleOrFinal = ModuleClass | Final
475+
476+
/** Either mutable or lazy */
477+
final val MutableOrLazy = Mutable | Lazy
478+
479+
/** Labeled `private` or `final` */
480+
final val PrivateOrFinal = Private | Final
481+
473482
/** A type parameter with synthesized name */
474483
final val ExpandedTypeParam = allOf(ExpandedName, TypeParam)
475484

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,12 @@ object SymDenotations {
586586
final def enclosingClass(implicit ctx: Context): Symbol =
587587
if (isClass || !exists) symbol else owner.enclosingClass
588588

589+
final def isEffectivelyFinal(implicit ctx: Context): Boolean = {
590+
(this.flags is Flags.PrivateOrFinal) || (!this.owner.isClass) ||
591+
((this.owner.flags is (Flags.ModuleOrFinal)) && (!this.flags.is(Flags.MutableOrLazy))) ||
592+
(this.owner.isAnonymousClass)
593+
}
594+
589595
/** The class containing this denotation which has the given effective name.
590596
*/
591597
final def enclosingClassNamed(name: Name)(implicit ctx: Context): Symbol = {

0 commit comments

Comments
 (0)