Permalink
Browse files

Move isFinalType logic to Symbol.

It's strictly based on the symbol, not the type.
  • Loading branch information...
1 parent 0693592 commit a65dbd7b98abd51b576471b4a6a4e9756dd23655 @paulp paulp committed Jan 2, 2013
Showing with 12 additions and 3 deletions.
  1. +11 −1 src/reflect/scala/reflect/internal/Symbols.scala
  2. +1 −2 src/reflect/scala/reflect/internal/Types.scala
@@ -574,6 +574,17 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
*/
def isEffectiveRoot = false
+ /** Can this symbol only be subclassed by bottom classes? This is assessed
+ * to be the case if it is final, and any type parameters are invariant.
+ */
+ def hasOnlyBottomSubclasses = {
+ def loop(tparams: List[Symbol]): Boolean = tparams match {
+ case Nil => true
+ case x :: xs => x.variance.isInvariant && loop(xs)
+ }
+ isClass && isFinal && loop(typeParams)
+ }
+
final def isLazyAccessor = isLazy && lazyAccessor != NoSymbol
final def isOverridableMember = !(isClass || isEffectivelyFinal) && (this ne NoSymbol) && owner.isClass
@@ -3286,7 +3297,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
// ----- Hoisted closures and convenience methods, for compile time reductions -------
private[scala] final val symbolIsPossibleInRefinement = (sym: Symbol) => sym.isPossibleInRefinement
- private[scala] final val symbolIsNonVariant = (sym: Symbol) => sym.variance.isInvariant
@tailrec private[scala] final
def allSymbolsHaveOwner(syms: List[Symbol], owner: Symbol): Boolean = syms match {
@@ -365,8 +365,7 @@ trait Types extends api.Types { self: SymbolTable =>
* This is assessed to be the case if the class is final,
* and all type parameters (if any) are invariant.
*/
- def isFinalType =
- typeSymbol.isFinal && (typeSymbol.typeParams forall symbolIsNonVariant)
+ def isFinalType = typeSymbol.hasOnlyBottomSubclasses
/** Is this type completed (i.e. not a lazy type)? */
def isComplete: Boolean = true

0 comments on commit a65dbd7

Please sign in to comment.