Skip to content

Commit

Permalink
more localness
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Dec 13, 2023
1 parent 24983a3 commit ea341fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/reflect/scala/reflect/internal/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1025,14 +1025,13 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
)
/** Is this symbol effectively final or a concrete term member of sealed class whose children do not override it */
final def isEffectivelyFinalOrNotOverridden: Boolean = {
def hasLocalOwner(c: Symbol) = { val k = c.originalOwner; k != NoSymbol && k.isTerm }
def isNotOverriddenAt(c: Symbol, hasLocalOwner: Boolean): Boolean = {
def checkOverrideIn(sc: Symbol) = overridingSymbol(sc) == NoSymbol && isNotOverriddenAt(sc, hasLocalOwner)
def checkOverrideIn(sc: Symbol) = overridingSymbol(sc) == NoSymbol && isNotOverriddenAt(sc, hasLocalOwner || sc.originalOwner.isTerm)
c.isClass && (c.isEffectivelyFinal || {
(c.isSealed || hasLocalOwner) && c.children.forall(checkOverrideIn)
})
}
isEffectivelyFinal || isTerm && !isDeferred && isNotOverriddenAt(owner, hasLocalOwner(originalOwner))
isEffectivelyFinal || isTerm && !isDeferred && isNotOverriddenAt(owner, owner.originalOwner.isTerm)
}

/** Is this symbol owned by a package? */
Expand Down
36 changes: 36 additions & 0 deletions test/files/pos/t9414.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,39 @@ object E {
def notBar = 42
}
}

class F {
def foo = {
class Parent {
@tailrec def bar: Int = {
println("here we go again")
bar
}
}
class K {
class Child extends Parent {
def notBar = 42
}
class GrandChild extends Child {
def neitherBar = 42
}
}
}
}

class G {
sealed class Parent {
@tailrec def bar: Int = {
println("here we go again")
bar
}
}
def foo = {
class Child extends Parent {
def notBar = 42
}
class GrandChild extends Child {
def neitherBar = 42
}
}
}

0 comments on commit ea341fa

Please sign in to comment.