summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2006-08-30 10:05:49 +0000
committermichelou <michelou@epfl.ch>2006-08-30 10:05:49 +0000
commit7cb834d07b2d291ef060eab504e8e44618e18b8c (patch)
treeee6ed93e7a4daba136873ce42caebb18468e3f74 /src/compiler/scala/tools/nsc/typechecker
parentbd0e709a7b10731d15084a733d5f661ad2b38dc1 (diff)
downloadscala-7cb834d07b2d291ef060eab504e8e44618e18b8c.tar.gz
scala-7cb834d07b2d291ef060eab504e8e44618e18b8c.tar.bz2
scala-7cb834d07b2d291ef060eab504e8e44618e18b8c.zip
removed leading/trailing tabs/blanks in typeche...
removed leading/trailing tabs/blanks in typechecker/*.scala
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala25
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala67
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala222
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala173
4 files changed, 265 insertions, 222 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
index a19c5799d4..49d06a16fc 100644
--- a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
@@ -1,15 +1,21 @@
-/* NSC -- new scala compiler
- * Copyright 2005 LAMP/EPFL
+/* NSC -- new Scala compiler
+ * Copyright 2005-2006 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
-package scala.tools.nsc.typechecker;
+package scala.tools.nsc.typechecker
+
+/** This class ...
+ *
+ * @author Martin Odersky
+ * @version 1.0
+ */
abstract class ConstantFolder {
- val global: Global;
- import global._;
- import definitions._;
+ val global: Global
+ import global._
+ import definitions._
/** If tree is a constant operation, replace with result. */
def apply(tree: Tree): Tree = fold(tree, tree match {
@@ -18,7 +24,12 @@ abstract class ConstantFolder {
case _ => null
})
- /** If tree is a constant value that can be converted to type `pt', perform the conversion */
+ /** If tree is a constant value that can be converted to type `pt', perform
+ * the conversion.
+ *
+ * @param tree ...
+ * @param pt ...
+ */
def apply(tree: Tree, pt: Type): Tree = fold(tree, tree.tpe match {
case ConstantType(x) => x convertTo pt
case _ => null
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 5891da326e..4fa5f5b1ea 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -1,13 +1,19 @@
-/* NSC -- new scala compiler
- * Copyright 2005 LAMP/EPFL
+/* NSC -- new Scala compiler
+ * Copyright 2005-2006 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
-package scala.tools.nsc.typechecker;
+
+package scala.tools.nsc.typechecker
import symtab.Flags._
import scala.tools.nsc.util.Position
+/** This trait ...
+ *
+ * @author Martin Odersky
+ * @version 1.0
+ */
trait Contexts requires Analyzer {
import global._
@@ -22,7 +28,8 @@ trait Contexts requires Analyzer {
definitions.RootClass,
definitions.RootClass.info.decls)
- def rootContext(unit: CompilationUnit): Context = rootContext(unit, EmptyTree, false)
+ def rootContext(unit: CompilationUnit): Context =
+ rootContext(unit, EmptyTree, false)
def rootContext(unit: CompilationUnit, tree: Tree, erasedTypes: boolean): Context = {
import definitions._
@@ -64,21 +71,22 @@ trait Contexts requires Analyzer {
class Context {
var unit: CompilationUnit = _
- var tree: Tree = _; // Tree associated with this context
- var owner: Symbol = NoSymbol; // The current owner
- var scope: Scope = _; // The current scope
- var outer: Context = _; // The next outer context
- var enclClass: Context = _; // The next outer context whose tree is a
+ var tree: Tree = _ // Tree associated with this context
+ var owner: Symbol = NoSymbol // The current owner
+ var scope: Scope = _ // The current scope
+ var outer: Context = _ // The next outer context
+ var enclClass: Context = _ // The next outer context whose tree is a
// template or package definition
- var enclMethod: Context = _; // The next outer context whose tree is a method
- var variance: int = _; // Variance relative to enclosing class.
- private var _undetparams: List[Symbol] = List(); // Undetermined type parameters, not inherited to child contexts
+ var enclMethod: Context = _ // The next outer context whose tree is a method
+ var variance: int = _ // Variance relative to enclosing class.
+ private var _undetparams: List[Symbol] = List() // Undetermined type parameters,
+ // not inherited to child contexts
var depth: int = 0
var imports: List[ImportInfo] = List()
var prefix: Type = NoPrefix
- var inConstructorSuffix = false; // are we in a secondary constructor
- // after the this constructor call?
+ var inConstructorSuffix = false // are we in a secondary constructor
+ // after the this constructor call?
var reportAmbiguousErrors = false
var reportGeneralErrors = false
var implicitsEnabled = false
@@ -93,7 +101,8 @@ trait Contexts requires Analyzer {
_undetparams = ps
}
- def make(unit: CompilationUnit, tree: Tree, owner: Symbol, scope: Scope, imports: List[ImportInfo]): Context = {
+ def make(unit: CompilationUnit, tree: Tree, owner: Symbol,
+ scope: Scope, imports: List[ImportInfo]): Context = {
val c = new Context
c.unit = unit
c.tree = tree
@@ -101,12 +110,14 @@ trait Contexts requires Analyzer {
c.scope = scope
tree match {
case Template(_, _) | PackageDef(_, _) =>
- c.enclClass = c;
+ c.enclClass = c
c.prefix = c.owner.thisType
c.inConstructorSuffix = false
case _ =>
c.enclClass = this.enclClass
- c.prefix = if (c.owner != this.owner && c.owner.isTerm) NoPrefix else this.prefix
+ c.prefix =
+ if (c.owner != this.owner && c.owner.isTerm) NoPrefix
+ else this.prefix
c.inConstructorSuffix = this.inConstructorSuffix
}
tree match {
@@ -166,7 +177,8 @@ trait Contexts requires Analyzer {
def makeConstructorContext = {
var baseContext = enclClass.outer
//todo: find out why we need next line
- while (baseContext.tree.isInstanceOf[Template]) baseContext = baseContext.outer
+ while (baseContext.tree.isInstanceOf[Template])
+ baseContext = baseContext.outer
val argContext = baseContext.makeNewScope(tree, owner)
for (val sym <- scope.toList) argContext.scope enter sym
argContext
@@ -178,12 +190,12 @@ trait Contexts requires Analyzer {
c
}
- def error(pos : Int, er : Error): Unit = {
- val msg = er.getMessage();
+ def error(pos: Int, er: Error): Unit = {
+ val msg = er.getMessage()
if (reportGeneralErrors)
unit.error(pos, if (checking) "**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg)
else
- throw er;
+ throw er
}
def error(pos: PositionType, msg: String): unit =
@@ -222,10 +234,17 @@ trait Contexts requires Analyzer {
override def toString(): String = {
if (this == NoContext) "NoContext"
- else owner.toString() + " @ " + tree.getClass() + " " + tree.toString() + ", scope = " + scope.hashCode() + " " + scope.toList + "\n:: " + outer.toString()
+ else owner.toString() + " @ " + tree.getClass() +
+ " " + tree.toString() + ", scope = " + scope.hashCode() +
+ " " + scope.toList + "\n:: " + outer.toString()
}
- /** Is `sym' accessible as a member of tree `site' with type `pre' in current context?
+ /** Is `sym' accessible as a member of tree `site' with type `pre' in
+ * current context?
+ *
+ * @param sym ...
+ * @param pre ...
+ * @param superAccess ...
*/
def isAccessible(sym: Symbol, pre: Type, superAccess: boolean): boolean = {
@@ -360,7 +379,7 @@ trait Contexts requires Analyzer {
if (tpeCache == null) tpeCache = pre.memberType(sym)
tpeCache
}
- override def toString = "ImplicitInfo("+name+","+pre+","+sym+")"
+ override def toString = "ImplicitInfo(" + name + "," + pre + "," + sym + ")"
}
val NoImplicitInfo = new ImplicitInfo(null, null, null)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 8059aa641c..be1c97c8b4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -1,28 +1,33 @@
-/* NSC -- new scala compiler
- * Copyright 2005 LAMP/EPFL
+/* NSC -- new Scala compiler
+ * Copyright 2005-2006 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
-package scala.tools.nsc.typechecker;
-import scala.tools.nsc.util.Position;
-import symtab.Flags;
-import symtab.Flags._;
+package scala.tools.nsc.typechecker
-/** Methods to create symbols and to enter them into scopes. */
+import scala.tools.nsc.util.Position
+import symtab.Flags
+import symtab.Flags._
+
+/** This trait declares methods to create symbols and to enter them into scopes.
+ *
+ * @author Martin Odersky
+ * @version 1.0
+ */
trait Namers requires Analyzer {
- import global._;
- import definitions._;
+ import global._
+ import definitions._
- /** Convert to corresponding type parameters all skolems which satisfy one of the
- * following two conditions:
+ /** Convert to corresponding type parameters all skolems which satisfy one
+ * of the following two conditions:
* 1. The skolem is a parameter of a class or alias type
* 2. The skolem is a method parameter which appears in parameter `tparams'
*/
class DeSkolemizeMap(tparams: List[Symbol]) extends TypeMap {
def apply(tp: Type): Type = tp match {
case TypeRef(pre, sym, args) =>
- val tparam = sym.deSkolemize;
+ val tparam = sym.deSkolemize
mapOver(
if (tparam == sym || !(tparams contains tparam)) tp
else rawTypeRef(NoPrefix, tparam, args))
@@ -31,8 +36,8 @@ trait Namers requires Analyzer {
case PolyType(tparams1, restpe) =>
new DeSkolemizeMap(tparams1 ::: tparams).mapOver(tp)
case ClassInfoType(parents, decls, clazz) =>
- val parents1 = List.mapConserve(parents)(this);
- if (parents1 eq parents) tp else ClassInfoType(parents1, decls, clazz);
+ val parents1 = List.mapConserve(parents)(this)
+ if (parents1 eq parents) tp else ClassInfoType(parents1, decls, clazz)
case _ =>
mapOver(tp)
}
@@ -40,7 +45,7 @@ trait Namers requires Analyzer {
class Namer(val context: Context) {
- val typer = newTyper(context);
+ val typer = newTyper(context)
def setPrivateWithin(tree: Tree, sym: Symbol, mods: Modifiers): Symbol = {
if (!mods.privateWithin.isEmpty)
@@ -70,18 +75,19 @@ trait Namers requires Analyzer {
case _ => false
}
- private var innerNamerCache: Namer = null;
+ private var innerNamerCache: Namer = null
def innerNamer: Namer = {
if (innerNamerCache == null)
- innerNamerCache = if (!isTemplateContext(context)) this
- else new Namer(context.make(context.tree, context.owner, newScope));
+ innerNamerCache =
+ if (!isTemplateContext(context)) this
+ else new Namer(context.make(context.tree, context.owner, newScope))
innerNamerCache
}
private def doubleDefError(pos: PositionType, sym: Symbol): unit =
context.error(pos,
sym.name.toString() + " is already defined as " +
- (if (sym.hasFlag(CASE)) "case class " + sym.name else sym.toString()));
+ (if (sym.hasFlag(CASE)) "case class " + sym.name else sym.toString()))
def enterInScope(sym: Symbol): Symbol = {
// allow for overloaded methods
@@ -101,14 +107,14 @@ trait Namers requires Analyzer {
private def enterPackageSymbol(pos: PositionType, name: Name): Symbol = {
val cscope = if (context.owner == EmptyPackageClass) RootClass.info.decls
else context.scope;
- val p: Symbol = cscope.lookup(name);
+ val p: Symbol = cscope.lookup(name)
if (p.isPackage && cscope == p.owner.info.decls) {
p
} else {
- val cowner = if (context.owner == EmptyPackageClass) RootClass else context.owner;
- val pkg = cowner.newPackage(pos, name);
- pkg.moduleClass.setInfo(new PackageClassInfoType(newScope, pkg.moduleClass));
- pkg.setInfo(pkg.moduleClass.tpe);
+ val cowner = if (context.owner == EmptyPackageClass) RootClass else context.owner
+ val pkg = cowner.newPackage(pos, name)
+ pkg.moduleClass.setInfo(new PackageClassInfoType(newScope, pkg.moduleClass))
+ pkg.setInfo(pkg.moduleClass.tpe)
enterInScope(pkg)
}
}
@@ -118,19 +124,19 @@ trait Namers requires Analyzer {
else 0l;
private def enterClassSymbol(pos: PositionType, flags: int, name: Name): Symbol = {
- var c: Symbol = context.scope.lookup(name);
+ var c: Symbol = context.scope.lookup(name)
if (c.isType && !currentRun.compiles(c) && context.scope == c.owner.info.decls) {
updatePosFlags(c, pos, flags);
} else {
c = enterInScope(context.owner.newClass(pos, name)).setFlag(flags | inConstructorFlag);
}
if (c.owner.isPackageClass) {
- val file = context.unit.source.getFile();
- val clazz = c.asInstanceOf[ClassSymbol];
+ val file = context.unit.source.getFile()
+ val clazz = c.asInstanceOf[ClassSymbol]
if (settings.debug.value && clazz.sourceFile != null && !clazz.sourceFile.equals(file)) {
System.err.println("SOURCE MISMATCH: " + clazz.sourceFile + " vs. " + file + " SYM=" + c);
}
- clazz.sourceFile = file;
+ clazz.sourceFile = file
if (clazz.sourceFile != null) {
assert(!currentRun.compiles(clazz) || clazz.sourceFile == currentRun.symSource(c));
currentRun.symSource(c) = clazz.sourceFile
@@ -140,33 +146,34 @@ trait Namers requires Analyzer {
}
private def enterModuleSymbol(pos: PositionType, flags: int, name: Name): Symbol = {
- var m: Symbol = context.scope.lookup(name);
- if (m.isModule && !m.isPackage && !currentRun.compiles(m) && (context.scope == m.owner.info.decls)) {
-
+ var m: Symbol = context.scope.lookup(name)
+ if (m.isModule && !m.isPackage && !currentRun.compiles(m) &&
+ (context.scope == m.owner.info.decls)) {
updatePosFlags(m, pos, flags)
} else {
if (m.isTerm && !m.isPackage && !currentRun.compiles(m) && (context.scope == m.owner.info.decls))
context.scope.unlink(m);
- m = context.owner.newModule(pos, name);
- m.setFlag(flags);
- m.moduleClass.setFlag(flags | inConstructorFlag);
+ m = context.owner.newModule(pos, name)
+ m.setFlag(flags)
+ m.moduleClass.setFlag(flags | inConstructorFlag)
enterInScope(m)
}
if (m.owner.isPackageClass) {
- m.moduleClass.sourceFile = context.unit.source.getFile();
+ m.moduleClass.sourceFile = context.unit.source.getFile()
currentRun.symSource(m) = m.moduleClass.sourceFile
}
m
}
private def enterCaseFactorySymbol(pos: PositionType, flags: int, name: Name): Symbol = {
- var m: Symbol = context.scope.lookup(name);
+ var m: Symbol = context.scope.lookup(name)
if (m.isTerm && !m.isPackage && !currentRun.compiles(m) && context.scope == m.owner.info.decls) {
updatePosFlags(m, pos, flags)
} else {
- m = enterInScope(context.owner.newMethod(pos, name)).setFlag(flags);
+ m = enterInScope(context.owner.newMethod(pos, name)).setFlag(flags)
}
- if (m.owner.isPackageClass) currentRun.symSource(m) = context.unit.source.getFile();
+ if (m.owner.isPackageClass)
+ currentRun.symSource(m) = context.unit.source.getFile()
m
}
@@ -174,7 +181,7 @@ trait Namers requires Analyzer {
(this /: trees) ((namer, tree) => namer.enterSym(tree));
def newTypeSkolems(tparams: List[Symbol]): List[Symbol] = {
- val tskolems = tparams map (.newTypeSkolem);
+ val tskolems = tparams map (.newTypeSkolem)
val ltp = new LazyType {
override def complete(sym: Symbol): unit =
sym setInfo sym.deSkolemize.info.substSym(tparams, tskolems);
@@ -184,7 +191,7 @@ trait Namers requires Analyzer {
}
def skolemize(tparams: List[AbsTypeDef]): unit = {
- val tskolems = newTypeSkolems(tparams map (.symbol));
+ val tskolems = newTypeSkolems(tparams map (.symbol))
for (val Pair(tparam, tskolem) <- tparams zip tskolems) tparam.symbol = tskolem
}
@@ -192,25 +199,25 @@ trait Namers requires Analyzer {
if (owner.isTerm || owner.isPackageClass) List()
else applicableTypeParams(owner.owner) ::: owner.typeParams;
- def deSkolemize: TypeMap = new DeSkolemizeMap(applicableTypeParams(context.owner));
+ def deSkolemize: TypeMap = new DeSkolemizeMap(applicableTypeParams(context.owner))
def enterSym(tree: Tree): Namer = {
def finishWith(tparams: List[AbsTypeDef]): unit = {
if (settings.debug.value) log("entered " + tree.symbol + " in " + context.owner + ", scope-id = " + context.scope.hashCode());
- var ltype: LazyType = innerNamer.typeCompleter(tree);
+ var ltype: LazyType = innerNamer.typeCompleter(tree)
if (!tparams.isEmpty) {
new Namer(context.makeNewScope(tree, tree.symbol)).enterSyms(tparams);
- ltype = new LazyPolyType(tparams map (.symbol), ltype);
+ ltype = new LazyPolyType(tparams map (.symbol), ltype)
if (tree.symbol.isTerm) skolemize(tparams);
}
- tree.symbol.setInfo(ltype);
+ tree.symbol.setInfo(ltype)
}
- def finish = finishWith(List());
+ def finish = finishWith(List())
if (tree.symbol == NoSymbol) {
- val owner = context.owner;
+ val owner = context.owner
tree match {
case PackageDef(name, stats) =>
tree.symbol = enterPackageSymbol(tree.pos, name);
@@ -224,14 +231,14 @@ trait Namers requires Analyzer {
.setInfo(innerNamer.caseFactoryCompleter(tree));
setPrivateWithin(tree, tree.symbol, mods);
}
- tree.symbol = enterClassSymbol(tree.pos, mods.flags, name);
- setPrivateWithin(tree, tree.symbol, mods);
- finishWith(tparams);
+ tree.symbol = enterClassSymbol(tree.pos, mods.flags, name)
+ setPrivateWithin(tree, tree.symbol, mods)
+ finishWith(tparams)
case ModuleDef(mods, name, _) =>
tree.symbol = enterModuleSymbol(tree.pos, mods.flags | MODULE | FINAL, name);
- setPrivateWithin(tree, tree.symbol, mods);
- setPrivateWithin(tree, tree.symbol.moduleClass, mods);
- tree.symbol.moduleClass.setInfo(innerNamer.moduleClassTypeCompleter(tree));
+ setPrivateWithin(tree, tree.symbol, mods)
+ setPrivateWithin(tree, tree.symbol.moduleClass, mods)
+ tree.symbol.moduleClass.setInfo(innerNamer.moduleClassTypeCompleter(tree))
finish
case ValDef(mods, name, tp, rhs) =>
if (context.owner.isClass & (mods.flags & LOCAL) == 0) {
@@ -263,23 +270,23 @@ trait Namers requires Analyzer {
}
case DefDef(mods, nme.CONSTRUCTOR, tparams, _, _, _) =>
tree.symbol = enterInScope(owner.newConstructor(tree.pos))
- .setFlag(mods.flags | owner.getFlag(ConstrFlags));
- setPrivateWithin(tree, tree.symbol, mods);
- finishWith(tparams);
+ .setFlag(mods.flags | owner.getFlag(ConstrFlags))
+ setPrivateWithin(tree, tree.symbol, mods)
+ finishWith(tparams)
case DefDef(mods, name, tparams, _, _, _) =>
tree.symbol = enterInScope(owner.newMethod(tree.pos, name))
- .setFlag(mods.flags);
- setPrivateWithin(tree, tree.symbol, mods);
- finishWith(tparams);
+ .setFlag(mods.flags)
+ setPrivateWithin(tree, tree.symbol, mods)
+ finishWith(tparams)
case AbsTypeDef(mods, name, _, _) =>
tree.symbol = enterInScope(owner.newAbstractType(tree.pos, name))
- .setFlag(mods.flags);
- setPrivateWithin(tree, tree.symbol, mods);
+ .setFlag(mods.flags)
+ setPrivateWithin(tree, tree.symbol, mods)
finish
case AliasTypeDef(mods, name, tparams, _) =>
tree.symbol = enterInScope(owner.newAliasType(tree.pos, name))
- .setFlag(mods.flags);
- setPrivateWithin(tree, tree.symbol, mods);
+ .setFlag(mods.flags)
+ setPrivateWithin(tree, tree.symbol, mods)
finishWith(tparams)
case DocDef(_, defn) =>
enterSym(defn)
@@ -297,10 +304,10 @@ trait Namers requires Analyzer {
def typeCompleter(tree: Tree) = new TypeCompleter(tree) {
override def complete(sym: Symbol): unit = {
if (settings.debug.value) log("defining " + sym);
- val tp = typeSig(tree);
- sym.setInfo(tp);
+ val tp = typeSig(tree)
+ sym.setInfo(tp)
if (settings.debug.value) log("defined " + sym);
- validate(sym);
+ validate(sym)
}
}
@@ -313,34 +320,34 @@ trait Namers requires Analyzer {
def getterTypeCompleter(tree: Tree) = new TypeCompleter(tree) {
override def complete(sym: Symbol): unit = {
if (settings.debug.value) log("defining " + sym);
- sym.setInfo(PolyType(List(), typeSig(tree)));
+ sym.setInfo(PolyType(List(), typeSig(tree)))
if (settings.debug.value) log("defined " + sym);
- validate(sym);
+ validate(sym)
}
}
def setterTypeCompleter(tree: Tree) = new TypeCompleter(tree) {
override def complete(sym: Symbol): unit = {
if (settings.debug.value) log("defining " + sym);
- sym.setInfo(MethodType(List(typeSig(tree)), UnitClass.tpe));
+ sym.setInfo(MethodType(List(typeSig(tree)), UnitClass.tpe))
if (settings.debug.value) log("defined " + sym);
- validate(sym);
+ validate(sym)
}
}
def selfTypeCompleter(tree: Tree) = new TypeCompleter(tree) {
override def complete(sym: Symbol): unit = {
- sym.setInfo(typer.typedType(tree).tpe);
+ sym.setInfo(typer.typedType(tree).tpe)
}
}
def caseFactoryCompleter(tree: Tree) = new TypeCompleter(tree) {
override def complete(sym: Symbol): unit = {
- val clazz = tree.symbol;
- var tpe = clazz.primaryConstructor.tpe;
- val tparams = clazz.typeParams;
+ val clazz = tree.symbol
+ var tpe = clazz.primaryConstructor.tpe
+ val tparams = clazz.typeParams
if (!tparams.isEmpty) tpe = PolyType(tparams, tpe).cloneInfo(sym);
- sym.setInfo(tpe);
+ sym.setInfo(tpe)
}
}
@@ -372,7 +379,7 @@ trait Namers requires Analyzer {
});
private def templateSig(templ: Template): Type = {
- val clazz = context.owner;
+ val clazz = context.owner
def checkParent(tpt: Tree): Type = {
val tp = tpt.tpe
if (tp.symbol == context.owner) {
@@ -399,10 +406,11 @@ trait Namers requires Analyzer {
makePolyType(tparamSyms, templateSig(impl))
}
- private def methodSig(tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): Type = {
- val meth = context.owner;
- val tparamSyms = typer.reenterTypeParams(tparams);
- val vparamSymss = enterValueParams(meth, vparamss);
+ private def methodSig(tparams: List[AbsTypeDef], vparamss: List[List[ValDef]],
+ tpt: Tree, rhs: Tree): Type = {
+ val meth = context.owner
+ val tparamSyms = typer.reenterTypeParams(tparams)
+ val vparamSymss = enterValueParams(meth, vparamss)
val restype =
if (tpt.isEmpty) {
tpt.tpe = if (meth.name == nme.CONSTRUCTOR) context.enclClass.owner.tpe
@@ -429,16 +437,16 @@ trait Namers requires Analyzer {
private def checkContractive(sym: Symbol, tp: Type): Type = {
/* The type signature without implicit parameters converted to function type */
def provided(tp: Type): Type = tp match {
- case PolyType(_, restpe) => provided(restpe);
- case mt: ImplicitMethodType => mt.resultType;
+ case PolyType(_, restpe) => provided(restpe)
+ case mt: ImplicitMethodType => mt.resultType
case MethodType(formals, restpe) => functionType(formals, provided(restpe))
case _ => tp
}
/* The types of all implicit parameters */
def required(tp: Type): List[Type] = tp match {
- case PolyType(_, restpe) => required(restpe);
- case mt: ImplicitMethodType => mt.paramTypes;
- case MethodType(formals, restpe) => required(restpe);
+ case PolyType(_, restpe) => required(restpe)
+ case mt: ImplicitMethodType => mt.paramTypes
+ case MethodType(formals, restpe) => required(restpe)
case _ => List()
}
var result = tp;
@@ -462,13 +470,13 @@ trait Namers requires Analyzer {
private def typeSig(tree: Tree): Type = {
val result =
try {
- val sym: Symbol = tree.symbol;
+ val sym: Symbol = tree.symbol
tree match {
case ClassDef(_, _, tparams, tpt, impl) =>
new Namer(context.makeNewScope(tree, sym)).classSig(tparams, tpt, impl)
case ModuleDef(_, _, impl) =>
- val clazz = sym.moduleClass;
+ val clazz = sym.moduleClass
clazz.setInfo(new Namer(context.make(tree, clazz)).templateSig(impl));
//clazz.typeOfThis = singleType(sym.owner.thisType, sym);
clazz.tpe;
@@ -506,9 +514,9 @@ trait Namers requires Analyzer {
TypeBounds(lt, ht)
case Import(expr, selectors) =>
- val expr1 = typer.typedQualifier(expr);
- val base = expr1.tpe;
- typer.checkStable(expr1);
+ val expr1 = typer.typedQualifier(expr)
+ val base = expr1.tpe
+ typer.checkStable(expr1)
def checkNotRedundant(pos: PositionType, from: Name, to: Name): boolean = {
if (!base.symbol.isPackage && base.member(from) != NoSymbol) {
val e = context.scope.lookupEntry(to)
@@ -541,13 +549,13 @@ trait Namers requires Analyzer {
checkSelectors(rest)
case Nil =>
}
- checkSelectors(selectors);
+ checkSelectors(selectors)
ImportType(expr1)
}
} catch {
case ex: TypeError =>
- //System.out.println("caught " + ex + " in typeSig");//DEBUG
- typer.reportTypeError(tree.pos, ex);
+ //System.out.println("caught " + ex + " in typeSig")//DEBUG
+ typer.reportTypeError(tree.pos, ex)
ErrorType
}
deSkolemize(result)
@@ -570,18 +578,18 @@ trait Namers requires Analyzer {
"illegal combination of modifiers: " +
Flags.flagsToString(flag1) + " and " + Flags.flagsToString(flag2));
if (sym.hasFlag(IMPLICIT) && !sym.isTerm)
- context.error(sym.pos, "`implicit' modifier can be used only for values, variables and methods");
+ context.error(sym.pos, "`implicit' modifier can be used only for values, variables and methods")
if (sym.hasFlag(IMPLICIT) && sym.owner.isPackageClass)
- context.error(sym.pos, "`implicit' modifier cannot be used for top-level objects");
+ context.error(sym.pos, "`implicit' modifier cannot be used for top-level objects")
if (sym.hasFlag(ABSTRACT) && !sym.isClass)
context.error(sym.pos, "`abstract' modifier can be used only for classes; " +
- "\nit should be omitted for abstract members");
+ "\nit should be omitted for abstract members")
if (sym.hasFlag(OVERRIDE | ABSOVERRIDE) && sym.isClass)
- context.error(sym.pos, "`override' modifier not allowed for classes");
+ context.error(sym.pos, "`override' modifier not allowed for classes")
if (sym.hasFlag(OVERRIDE | ABSOVERRIDE) && sym.isConstructor)
- context.error(sym.pos, "`override' modifier not allowed for constructors");
+ context.error(sym.pos, "`override' modifier not allowed for constructors")
if (sym.hasFlag(ABSOVERRIDE) && !sym.owner.isTrait)
- context.error(sym.pos, "`abstract override' modifier only allowed for members of traits");
+ context.error(sym.pos, "`abstract override' modifier only allowed for members of traits")
if (sym.info.symbol == FunctionClass(0) &&
sym.isValueParameter && sym.owner.isClass && sym.owner.hasFlag(CASE))
context.error(sym.pos, "pass-by-name arguments not allowed for case class parameters");
@@ -592,21 +600,21 @@ trait Namers requires Analyzer {
"only classes can have declared but undefined members" +
(if (!sym.isVariable) ""
else "\n(Note that variables need to be initialized to be defined)"));
- sym.resetFlag(DEFERRED);
+ sym.resetFlag(DEFERRED)
}
}
- checkNoConflict(DEFERRED, PRIVATE);
- checkNoConflict(FINAL, SEALED);
- checkNoConflict(PRIVATE, PROTECTED);
- checkNoConflict(PRIVATE, OVERRIDE);
- checkNoConflict(DEFERRED, FINAL);
+ checkNoConflict(DEFERRED, PRIVATE)
+ checkNoConflict(FINAL, SEALED)
+ checkNoConflict(PRIVATE, PROTECTED)
+ checkNoConflict(PRIVATE, OVERRIDE)
+ checkNoConflict(DEFERRED, FINAL)
}
}
/* Is type `tp1' properly contained in type `tp2'? */
def isContainedIn(tp1: Type, tp2: Type) = {
//System.out.println("is " + tp1 + " contained in " + tp2 + "?");//DEBUG
- new ContainsTraverser(tp1).traverse(tp2).result;
+ new ContainsTraverser(tp1).traverse(tp2).result
}
/* Type `elemtp' is contained in type `tp' is one of the following holds:
@@ -618,7 +626,7 @@ trait Namers requires Analyzer {
*/
private class ContainsTraverser(elemtp: Type) extends TypeTraverser {
var nested = false
- var result = false;
+ var result = false
def traverse(tp: Type): ContainsTraverser = {
if (!result) {
if (elemtp =:= tp)
@@ -645,6 +653,6 @@ trait Namers requires Analyzer {
}
}
- abstract class TypeCompleter(val tree: Tree) extends LazyType;
+ abstract class TypeCompleter(val tree: Tree) extends LazyType
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 478e3e206b..55d1511594 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1,13 +1,14 @@
-/* NSC -- new scala compiler
- * Copyright 2005 LAMP/EPFL
+/* NSC -- new Scala compiler
+ * Copyright 2005-2006 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
-package scala.tools.nsc.typechecker;
-import symtab.Flags._;
-import collection.mutable.HashMap;
-import transform.InfoTransform;
+package scala.tools.nsc.typechecker
+
+import symtab.Flags._
+import collection.mutable.HashMap
+import transform.InfoTransform
/** Post-attribution checking and transformation.
* //todo: check whether we always check type parameter bounds.
@@ -24,27 +25,30 @@ import transform.InfoTransform;
* - Local modules are replaced by variables and classes
* - Calls to case factory methods are replaced by new's.
* - eliminate branches in a conditional if the condition is a constant
+ *
+ * @author Martin Odersky
+ * @version 1.0
*/
abstract class RefChecks extends InfoTransform {
- import global._;
- import definitions._;
- import typer.{typed, typedOperator, atOwner};
- import posAssigner.atPos;
+ import global._
+ import definitions._
+ import typer.{typed, typedOperator, atOwner}
+ import posAssigner.atPos
/** the following two members override abstract members in Transform */
- val phaseName: String = "refchecks";
- override def phaseNewFlags: long = lateMETHOD;
+ val phaseName: String = "refchecks"
+ override def phaseNewFlags: long = lateMETHOD
- def newTransformer(unit: CompilationUnit): RefCheckTransformer = new RefCheckTransformer(unit);
- override def changesBaseClasses = false;
+ def newTransformer(unit: CompilationUnit): RefCheckTransformer =
+ new RefCheckTransformer(unit)
+ override def changesBaseClasses = false
- def transformInfo(sym: Symbol, tp: Type): Type = {
+ def transformInfo(sym: Symbol, tp: Type): Type =
if (sym.isModule && !sym.isStatic) {
- sym setFlag (lateMETHOD | STABLE);
+ sym setFlag (lateMETHOD | STABLE)
PolyType(List(), tp)
} else tp
- }
class RefCheckTransformer(unit: CompilationUnit) extends Transformer {
@@ -74,7 +78,7 @@ abstract class RefChecks extends InfoTransform {
*/
private def checkAllOverrides(clazz: Symbol): unit = {
- val self = clazz.thisType;
+ val self = clazz.thisType
def infoString(sym: Symbol) = (
sym.toString() +
@@ -99,7 +103,7 @@ abstract class RefChecks extends InfoTransform {
/* Check that all conditions for overriding `other' by `member' are met. */
def checkOverride(clazz: Symbol, member: Symbol, other: Symbol): unit = {
- val pos = if (member.owner == clazz) member.pos else clazz.pos;
+ val pos = if (member.owner == clazz) member.pos else clazz.pos
def overrideError(msg: String): unit =
if (other.tpe != ErrorType && member.tpe != ErrorType)
@@ -187,7 +191,7 @@ abstract class RefChecks extends InfoTransform {
}
}
- val opc = new overridingPairs.Cursor(clazz);
+ val opc = new overridingPairs.Cursor(clazz)
while (opc.hasNext) {
//System.out.println("overrides " + opc.overriding/* + ":" + opc.overriding.tpe*/ + opc.overriding.locationString + " " + opc.overridden/* + ":" + opc.overridden.tpe*/ + opc.overridden.locationString + opc.overridden.hasFlag(DEFERRED));//DEBUG
if (!opc.overridden.isClass) checkOverride(clazz, opc.overriding, opc.overridden);
@@ -224,7 +228,7 @@ abstract class RefChecks extends InfoTransform {
(if (clazz.isAnonymousClass || clazz.isModuleClass) "object creation impossible"
else if (mustBeMixin) clazz.toString() + " needs to be a mixin"
else clazz.toString() + " needs to be abstract") + ", since " + msg);
- clazz.setFlag(ABSTRACT);
+ clazz.setFlag(ABSTRACT)
}
for (val member <- clazz.tpe.members)
if ((member hasFlag DEFERRED) && !(clazz hasFlag ABSTRACT)) {
@@ -262,8 +266,8 @@ abstract class RefChecks extends InfoTransform {
* 3. Check that at most one base type is a case-class.
*/
private def validateBaseTypes(clazz: Symbol): unit = {
- val seenTypes = new Array[Type](clazz.info.closure.length);
- var seenCaseClass = if (clazz hasFlag CASE) clazz else NoSymbol;
+ val seenTypes = new Array[Type](clazz.info.closure.length)
+ var seenCaseClass = if (clazz hasFlag CASE) clazz else NoSymbol
def validateTypes(tps: List[Type], includeSuper: boolean): unit = {
if (!tps.isEmpty) {
@@ -273,9 +277,9 @@ abstract class RefChecks extends InfoTransform {
}
def validateType(tp: Type, includeSuper: boolean): unit = {
- val baseClass = tp.symbol;
+ val baseClass = tp.symbol
if (baseClass.isClass) {
- val index = clazz.info.closurePos(baseClass);
+ val index = clazz.info.closurePos(baseClass)
if (index >= 0) {
if (seenTypes(index) != null && !(seenTypes(index) <:< tp))
unit.error(clazz.pos, "illegal inheritance;\n " + clazz +
@@ -286,23 +290,24 @@ abstract class RefChecks extends InfoTransform {
if (baseClass hasFlag CASE) {
if (seenCaseClass != NoSymbol && seenCaseClass != baseClass)
unit.error(clazz.pos, "implementation restriction: case " +
- seenCaseClass + " and case " + baseClass + " cannot be combined in one object");
+ seenCaseClass + " and case " + baseClass +
+ " cannot be combined in one object");
seenCaseClass = baseClass
}
}
- validateTypes(tp.parents, includeSuper);
+ validateTypes(tp.parents, includeSuper)
}
}
- validateTypes(clazz.info.parents, true);
+ validateTypes(clazz.info.parents, true)
}
// Variance Checking --------------------------------------------------------
- private val ContraVariance = -1;
- private val NoVariance = 0;
- private val CoVariance = 1;
- private val AnyVariance = 2;
+ private val ContraVariance = -1
+ private val NoVariance = 0
+ private val CoVariance = 1
+ private val AnyVariance = 2
/** Check variance of type variables in this type
*/
@@ -314,15 +319,15 @@ abstract class RefChecks extends InfoTransform {
else "invariant";
def relativeVariance(tvar: Symbol): int = {
- val clazz = tvar.owner;
- var sym = base;
- var state = CoVariance;
+ val clazz = tvar.owner
+ var sym = base
+ var state = CoVariance
while (sym != clazz && state != AnyVariance) {
//System.out.println("flip: " + sym + " " + sym.isParameter());//DEBUG
if ((sym hasFlag PARAM) && !sym.owner.isConstructor) state = -state;
else if (!sym.owner.isClass) state = AnyVariance;
else if (sym.isAliasType) state = NoVariance;
- sym = sym.owner;
+ sym = sym.owner
}
state
}
@@ -347,23 +352,23 @@ abstract class RefChecks extends InfoTransform {
" position in type " + all + " of " + base);
}
}
- validateVariance(pre, variance);
- validateVarianceArgs(args, variance, sym.typeParams);
+ validateVariance(pre, variance)
+ validateVarianceArgs(args, variance, sym.typeParams)
case ClassInfoType(parents, decls, symbol) =>
- validateVariances(parents, variance);
+ validateVariances(parents, variance)
case RefinedType(parents, decls) =>
- validateVariances(parents, variance);
+ validateVariances(parents, variance)
case TypeBounds(lo, hi) =>
- validateVariance(lo, -variance);
- validateVariance(hi, variance);
+ validateVariance(lo, -variance)
+ validateVariance(hi, variance)
case MethodType(formals, result) =>
- validateVariance(result, variance);
+ validateVariance(result, variance)
case PolyType(tparams, result) =>
- validateVariance(result, variance);
+ validateVariance(result, variance)
}
def validateVariances(tps: List[Type], variance: int): unit =
- tps foreach (tp => validateVariance(tp, variance));
+ tps foreach (tp => validateVariance(tp, variance))
def validateVarianceArgs(tps: List[Type], variance: int, tparams: List[Symbol]): unit =
(tps zip tparams) foreach {
@@ -376,23 +381,23 @@ abstract class RefChecks extends InfoTransform {
// Forward reference checking ---------------------------------------------------
class LevelInfo(val outer: LevelInfo) {
- val scope: Scope = if (outer == null) newScope else newScope(outer.scope);
- var maxindex: int = Integer.MIN_VALUE;
- var refpos: int = _;
- var refsym: Symbol = _;
+ val scope: Scope = if (outer == null) newScope else newScope(outer.scope)
+ var maxindex: int = Integer.MIN_VALUE
+ var refpos: int = _
+ var refsym: Symbol = _
}
- private var currentLevel: LevelInfo = null;
- private val symIndex = new HashMap[Symbol, int];
+ private var currentLevel: LevelInfo = null
+ private val symIndex = new HashMap[Symbol, int]
private def pushLevel(): unit =
- currentLevel = new LevelInfo(currentLevel);
+ currentLevel = new LevelInfo(currentLevel)
private def popLevel(): unit =
- currentLevel = currentLevel.outer;
+ currentLevel = currentLevel.outer
private def enterSyms(stats: List[Tree]): unit = {
- var index = -1;
+ var index = -1
for (val stat <- stats) {
index = index + 1;
stat match {
@@ -409,15 +414,15 @@ abstract class RefChecks extends InfoTransform {
private def enterReference(pos: int, sym: Symbol): unit =
if (sym.isLocal) {
- val e = currentLevel.scope.lookupEntry(sym.name);
+ val e = currentLevel.scope.lookupEntry(sym.name)
if (e != null && sym == e.sym) {
- var l = currentLevel;
+ var l = currentLevel
while (l.scope != e.owner) l = l.outer;
- val symindex = symIndex(sym);
+ val symindex = symIndex(sym)
if (l.maxindex < symindex) {
- l.refpos = pos;
- l.refsym = sym;
- l.maxindex = symindex;
+ l.refpos = pos
+ l.refsym = sym
+ l.maxindex = symindex
}
}
}
@@ -425,17 +430,17 @@ abstract class RefChecks extends InfoTransform {
// Transformation ------------------------------------------------------------
override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
- pushLevel();
- enterSyms(stats);
- var index = -1;
+ pushLevel()
+ enterSyms(stats)
+ var index = -1
val stats1 = stats flatMap { stat => index = index + 1; transformStat(stat, index) }
- popLevel();
+ popLevel()
stats1
}
def transformStat(tree: Tree, index: int): List[Tree] = tree match {
case ModuleDef(mods, name, impl) =>
- val sym = tree.symbol;
+ val sym = tree.symbol
val cdef = ClassDef(mods | MODULE, name, List(), EmptyTree, impl)
.setPos(tree.pos)
.setSymbol(sym.moduleClass)
@@ -480,7 +485,7 @@ abstract class RefChecks extends InfoTransform {
/* Convert a reference of a case factory to a new of the class it produces. */
def toConstructor: Tree = {
- var tpe = tree.tpe;
+ var tpe = tree.tpe
while (!tpe.symbol.isClass) tpe = tpe.resultType;
assert(tpe.symbol hasFlag CASE);
typedOperator(atPos(tree.pos)(Select(New(TypeTree(tpe)), tpe.symbol.primaryConstructor)));
@@ -515,30 +520,30 @@ abstract class RefChecks extends InfoTransform {
result
}
- val savedLocalTyper = localTyper;
- val sym = tree.symbol;
- var result = tree;
+ val savedLocalTyper = localTyper
+ val sym = tree.symbol
+ var result = tree
tree match {
case ClassDef(mods, name, tparams, tpe, impl) =>
- validateVariance(sym, sym.info, CoVariance);
- validateVariance(sym, sym.typeOfThis, CoVariance);
+ validateVariance(sym, sym.info, CoVariance)
+ validateVariance(sym, sym.typeOfThis, CoVariance)
case DefDef(_, _, _, _, _, _) =>
- validateVariance(sym, sym.tpe, CoVariance);
+ validateVariance(sym, sym.tpe, CoVariance)
case ValDef(_, _, _, _) =>
validateVariance(sym, sym.tpe, if (sym.isVariable) NoVariance else CoVariance);
case AbsTypeDef(_, _, _, _) =>
- validateVariance(sym, sym.info, CoVariance);
+ validateVariance(sym, sym.info, CoVariance)
case AliasTypeDef(_, _, _, _) =>
- validateVariance(sym, sym.info, CoVariance);
+ validateVariance(sym, sym.info, CoVariance)
case Template(_, _) =>
- localTyper = localTyper.atOwner(tree, currentOwner);
- validateBaseTypes(currentOwner);
- checkAllOverrides(currentOwner);
+ localTyper = localTyper.atOwner(tree, currentOwner)
+ validateBaseTypes(currentOwner)
+ checkAllOverrides(currentOwner)
case TypeTree() =>
new TypeTraverser {
@@ -549,7 +554,7 @@ abstract class RefChecks extends InfoTransform {
} traverse tree.tpe
case TypeApply(fn, args) =>
- checkBounds(fn.tpe.typeParams, args map (.tpe));
+ checkBounds(fn.tpe.typeParams, args map (.tpe))
if (sym.isSourceMethod && sym.hasFlag(CASE)) result = toConstructor;
case Apply(
@@ -570,14 +575,14 @@ abstract class RefChecks extends InfoTransform {
}
case New(tpt) =>
- enterReference(tree.pos, tpt.tpe.symbol);
+ enterReference(tree.pos, tpt.tpe.symbol)
case Ident(name) =>
if (sym.isSourceMethod && sym.hasFlag(CASE))
result = toConstructor
else if (name != nme.WILDCARD && name != nme.WILDCARD_STAR.toTypeName) {
- assert(sym != NoSymbol, tree);//debug
- enterReference(tree.pos, sym);
+ assert(sym != NoSymbol, tree)//debug
+ enterReference(tree.pos, sym)
}
case Select(qual, name) =>
@@ -592,13 +597,13 @@ abstract class RefChecks extends InfoTransform {
}
case _ =>
}
- result = super.transform(result);
- localTyper = savedLocalTyper;
+ result = super.transform(result)
+ localTyper = savedLocalTyper
result
} catch {
case ex: TypeError =>
if (settings.debug.value) ex.printStackTrace();
- unit.error(tree.pos, ex.getMessage());
+ unit.error(tree.pos, ex.getMessage())
tree
}
}