summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-01-30 15:40:23 +0000
committerMartin Odersky <odersky@gmail.com>2007-01-30 15:40:23 +0000
commit2aee8120ee96800ba607e12079b4d3adb639be5c (patch)
tree4ef6a4659e812ab4ac2cfd8f7aedfc0416af13ff
parent4a64ac9c7b94b249087cd25712dfb547013f5ed4 (diff)
downloadscala-2aee8120ee96800ba607e12079b4d3adb639be5c.tar.gz
scala-2aee8120ee96800ba607e12079b4d3adb639be5c.tar.bz2
scala-2aee8120ee96800ba607e12079b4d3adb639be5c.zip
added subClasses method to symbols.
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala14
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala15
2 files changed, 23 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index dab6870aeb..644544cb2d 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -23,6 +23,7 @@ trait Symbols requires SymbolTable {
type AttrInfo = Triple[Type, List[Constant], List[Pair[Name,Constant]]]
val emptySymbolArray = new Array[Symbol](0)
+ val emptySymbolSet = Set.empty[Symbol]
type PositionType;
def NoPos : PositionType;
def FirstPos : PositionType;
@@ -867,6 +868,14 @@ trait Symbols requires SymbolTable {
def isFromClassFile: Boolean =
(if (isModule) moduleClass else toplevelClass).isFromClassFile
+ /** If this is a sealed class, its known subclasses. Otherwise Set.empty */
+ def subClasses: Set[Symbol] = emptySymbolSet
+
+ /** Declare given subclass `sym' of this sealed class */
+ def addSubClass(sym: Symbol) {
+ throw new Error("addSubClass_= inapplicable for " + this)
+ }
+
// ToString -------------------------------------------------------------------
@@ -1175,6 +1184,7 @@ trait Symbols requires SymbolTable {
/** The classfile from which this class was loaded. Maybe null. */
var classFile: AbstractFile = null;
+
private var source: AbstractFile = null
override def sourceFile =
if (owner.isPackageClass) source else super.sourceFile
@@ -1244,6 +1254,10 @@ trait Symbols requires SymbolTable {
override def sourceModule =
if (isModuleClass) linkedModuleOfClass else NoSymbol
+ private var subClassSet: Set[Symbol] = emptySymbolSet
+ override def subClasses: Set[Symbol] = subClassSet
+ override def addSubClass(sym: Symbol) { subClassSet = subClassSet + sym }
+
if (util.Statistics.enabled) classSymbolCount = classSymbolCount + 1
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index a90472d56b..e13bc27aff 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -774,9 +774,9 @@ trait Typers requires Analyzer {
def validateParentClass(parent: Tree, superclazz: Symbol): unit = {
if (!parent.tpe.isError) {
val psym = parent.tpe.symbol.initialize
- if (!psym.isClass)
+ if (!psym.isClass) {
error(parent.pos, "class type expected")
- else if (psym != superclazz)
+ } else if (psym != superclazz) {
if (psym.isTrait) {
val ps = psym.info.parents
if (!ps.isEmpty && !superclazz.isSubClass(ps.head.symbol))
@@ -788,11 +788,14 @@ trait Typers requires Analyzer {
}else {
error(parent.pos, ""+psym+" needs to be a trait be mixed in")
}
- else if (psym hasFlag FINAL)
+ } else if (psym hasFlag FINAL) {
error(parent.pos, "illegal inheritance from final class")
- else if (!phase.erasedTypes && psym.isSealed &&
- context.unit.source.file != psym.sourceFile)
- error(parent.pos, "illegal inheritance from sealed "+psym)
+ } else if (psym.isSealed && !phase.erasedTypes) {
+ if (context.unit.source.file != psym.sourceFile)
+ error(parent.pos, "illegal inheritance from sealed "+psym)
+ else
+ psym addSubClass context.owner
+ }
if (!(selfType <:< parent.tpe.typeOfThis) && !phase.erasedTypes) {
//Console.println(context.owner);//DEBUG
//Console.println(context.owner.unsafeTypeParams);//DEBUG