summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-06-29 20:44:07 +0000
committerPaul Phillips <paulp@improving.org>2011-06-29 20:44:07 +0000
commitf1c6c803da9766390203c195848e8d38256e8185 (patch)
treeb034ace739940552498bdb98a9f941b1859bb9e0
parent7c15ff1c2a24856cd2b9541c756b7e72f04d5848 (diff)
downloadscala-f1c6c803da9766390203c195848e8d38256e8185.tar.gz
scala-f1c6c803da9766390203c195848e8d38256e8185.tar.bz2
scala-f1c6c803da9766390203c195848e8d38256e8185.zip
Some further changes related to r23434.
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala15
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala9
3 files changed, 12 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index ef295acd02..bba07794e7 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -1294,7 +1294,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
/** For a module its linked class, for a class its linked module or case
* factory otherwise.
* Note: does not work for modules owned by methods, see
- * Namers.companionModuleOf / Namers.companionClassOf
+ * Namers.companionSymbolOf
*/
final def companionSymbol: Symbol =
if (isTerm) companionClass
@@ -2108,7 +2108,9 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
}
case class InvalidCompanions(sym1: Symbol, sym2: Symbol)
- extends Throwable("Companions '" + sym1 + "' and '" + sym2 + "' must be defined in same file")
+ extends Throwable("Companions '" + sym1 + "' and '" + sym2 + "' must be defined in same file") {
+ override def toString = getMessage
+ }
/** A class for type histories */
private sealed case class TypeHistory(var validFrom: Period, info: Type, prev: TypeHistory) {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 07cce81565..f873a7118f 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -90,11 +90,12 @@ trait Namers { self: Analyzer =>
sym.flags = flags | lockedFlag
if (sym.isModule && sym.moduleClass != NoSymbol)
updatePosFlags(sym.moduleClass, pos, moduleClassFlags(flags))
- if (sym.owner.isPackageClass &&
- (sym.companionSymbol.rawInfo.isInstanceOf[loaders.SymbolLoader] ||
- sym.companionSymbol.rawInfo.isComplete && runId(sym.validTo) != currentRunId))
+ var companion: Symbol = NoSymbol
+ if (sym.owner.isPackageClass && {companion = companionSymbolOf(sym, context); true} &&
+ (companion.rawInfo.isInstanceOf[loaders.SymbolLoader] ||
+ companion.rawInfo.isComplete && runId(sym.validTo) != currentRunId))
// pre-set linked symbol to NoType, in case it is not loaded together with this symbol.
- sym.companionSymbol.setInfo(NoType)
+ companion.setInfo(NoType)
sym
}
@@ -1382,7 +1383,7 @@ trait Namers { self: Analyzer =>
* Finds the companion module of a class symbol. Calling .companionModule
* does not work for classes defined inside methods.
*/
- def companionModuleOf(clazz: Symbol, context: Context) = {
+ def companionModuleOf(clazz: Symbol, context: Context) =
try {
var res = clazz.companionModule
if (res == NoSymbol)
@@ -1394,9 +1395,8 @@ trait Namers { self: Analyzer =>
context.error(clazz.pos, e.getMessage)
NoSymbol
}
- }
- def companionClassOf(module: Symbol, context: Context) = {
+ def companionClassOf(module: Symbol, context: Context) =
try {
var res = module.companionClass
if (res == NoSymbol)
@@ -1407,7 +1407,6 @@ trait Namers { self: Analyzer =>
context.error(module.pos, e.getMessage)
NoSymbol
}
- }
def companionSymbolOf(sym: Symbol, context: Context) =
if (sym.isTerm) companionClassOf(sym, context)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 1bf51973ba..3b2c5263e3 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1340,14 +1340,7 @@ trait Typers { self: Analyzer =>
// attributes(mdef)
// initialize all constructors of the linked class: the type completer (Namer.methodSig)
// might add default getters to this object. example: "object T; class T(x: Int = 1)"
- val linkedClass =
- try {
- mdef.symbol.companionClass
- } catch {
- case e: InvalidCompanions =>
- context.error(mdef.symbol.pos, e.getMessage)
- NoSymbol
- }
+ val linkedClass = companionClassOf(mdef.symbol, context)
if (linkedClass != NoSymbol)
for (c <- linkedClass.info.decl(nme.CONSTRUCTOR).alternatives)
c.initialize