summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2006-11-22 16:22:05 +0000
committerMartin Odersky <odersky@gmail.com>2006-11-22 16:22:05 +0000
commit4af77453d44c809c1ac06e78a8b698e2ef28a79d (patch)
tree1ac21e83729ff3cac7af9a6d34b34ea8a7109faf /src/compiler/scala/tools/nsc
parentf7e598a6a96719eed46c2c9e8f2a8e74e5533d24 (diff)
downloadscala-4af77453d44c809c1ac06e78a8b698e2ef28a79d.tar.gz
scala-4af77453d44c809c1ac06e78a8b698e2ef28a79d.tar.bz2
scala-4af77453d44c809c1ac06e78a8b698e2ef28a79d.zip
1.
2. Modified ambiguous check for implicits. 3. Cleanup of AddInterfaces
Diffstat (limited to 'src/compiler/scala/tools/nsc')
-rw-r--r--src/compiler/scala/tools/nsc/CompilationUnits.scala4
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala4
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala3
-rw-r--r--src/compiler/scala/tools/nsc/transform/AddInterfaces.scala18
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala33
6 files changed, 35 insertions, 31 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala
index 24f4cf7497..8e2f9f14b7 100644
--- a/src/compiler/scala/tools/nsc/CompilationUnits.scala
+++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala
@@ -38,6 +38,10 @@ trait CompilationUnits requires Global {
if (settings.deprecation.value) reporter.warning(position(pos), msg)
else currentRun.deprecationWarnings = true
+ def uncheckedWarning(pos: int, msg: String) =
+ if (settings.unchecked.value) reporter.warning(position(pos), msg)
+ else currentRun.uncheckedWarnings = true
+
override def toString() = source.toString()
def clear() = {
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 7e88d0dd13..eebbf739ed 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -390,6 +390,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
/** Deprecation warnings occurred */
var deprecationWarnings: boolean = false
+ var uncheckedWarnings: boolean = false
private var p: Phase = firstPhase
private var stopped = false
@@ -497,6 +498,9 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
if (deprecationWarnings) {
warning("there were deprecation warnings; re-run with -deprecation for details")
}
+ if (uncheckedWarnings) {
+ warning("there were unchecked warnings; re-run with -unchecked for details")
+ }
} else {
for (val Pair(sym, file) <- symSource.elements) {
sym.reset(new loaders.SourcefileLoader(file))
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index b4b9f02efc..e3c7c019f0 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -92,7 +92,8 @@ class Settings(error: String => unit) {
val target = ChoiceSetting ("-target", "Specify which backend to use", List("jvm-1.5", "jvm-1.4", "msil", "cldc"), "jvm-1.4")
val migrate = BooleanSetting("-migrate", "Assist in migrating from Scala version 1.0")
val debug = new BooleanSetting("-debug", "Output debugging messages") { override def hiddenToIDE = true }
- val deprecation = BooleanSetting ("-deprecation", "enable detailed deprecatation warnings")
+ val deprecation = BooleanSetting ("-deprecation", "enable detailed deprecation warnings")
+ val unchecked = BooleanSetting ("-unchecked", "enable detailed unchecked warnings")
val statistics = new BooleanSetting("-statistics", "Print compiler statistics") { override def hiddenToIDE = true }
val explaintypes = BooleanSetting("-explaintypes", "Explain type errors in more detail")
val resident = new BooleanSetting("-resident", "Compiler stays resident, files to compile are read from standard input") { override def hiddenToIDE = true }
diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
index c6dae63c2f..e09804c52b 100644
--- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
+++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
@@ -75,18 +75,7 @@ abstract class AddInterfaces extends InfoTransform {
if (impl == NoSymbol) {
impl = iface.cloneSymbolImpl(iface.owner)
impl.name = implName
- if (iface.owner.isClass) {
- atPhase(currentRun.erasurePhase.next) {
- val decls = iface.owner.info.decls
- val e = decls.lookupEntry(impl.name)
- if (e eq null) {
- decls enter impl
- } else {
- decls.unlink(e)
- decls enter impl
- }
- }
- }
+ iface.owner.info.decls enter impl
}
if (currentRun.compiles(iface)) currentRun.symSource(impl) = iface.sourceFile
impl setPos iface.pos
@@ -158,8 +147,7 @@ abstract class AddInterfaces extends InfoTransform {
override def complete(sym: Symbol): unit = {
def implType(tp: Type): Type = tp match {
case ClassInfoType(parents, decls, _) =>
- //Console.println("completing "+sym+" at "+phase+", decls = "+decls)
- //ClassInfoType(mixinToImplClass(parents) ::: List(iface.tpe), implDecls(sym, 0decls), sym)
+ assert(phase == implClassPhase, sym)
ClassInfoType(
ObjectClass.tpe :: (parents.tail map mixinToImplClass) ::: List(iface.tpe),
implDecls(sym, decls),
@@ -167,7 +155,7 @@ abstract class AddInterfaces extends InfoTransform {
case PolyType(tparams, restpe) =>
implType(restpe)
}
- sym.setInfo(atPhase(implClassPhase)(implType(atPhase(currentRun.erasurePhase)(iface.info))))
+ sym.setInfo(implType(atPhase(currentRun.erasurePhase)(iface.info)))
}
override def load(clazz: Symbol): unit = complete(clazz)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 74436c9bed..b772ff4ea0 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -785,7 +785,7 @@ trait Infer requires Analyzer {
def checkCheckable(pos: PositionType, tp: Type): unit = {
def patternWarning(tp: Type, prefix: String) =
- context.unit.deprecationWarning(pos, prefix+tp+" in type pattern is deprecated because it cannot be checked after erasure")
+ context.unit.uncheckedWarning(pos, prefix+tp+" in type pattern is unchecked since it is eliminated by erasure")
def isLocalBinding(sym: Symbol) =
sym.isAbstractType &&
(sym.name == nme.WILDCARD.toTypeName || {
@@ -815,7 +815,7 @@ trait Infer requires Analyzer {
case NoPrefix =>
;
case _ =>
- patternWarning(tp, "type pattern ")
+ patternWarning(tp, "type ")
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 52096ffbcd..932cfeced3 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2384,13 +2384,15 @@ trait Typers requires Analyzer {
val tc = newTyper(context.makeImplicit(reportAmbiguous))
- def ambiguousError(info1: ImplicitInfo, info2: ImplicitInfo) =
+ def ambiguousError(info1: ImplicitInfo, info2: ImplicitInfo,
+ pre1: String, pre2: String, trailer: String) =
error(
pos,
- "ambiguous implicit value:\n" +
- " both "+info1.sym + info1.sym.locationString+" of type "+info1.tpe+
- "\n and "+info2.sym + info2.sym.locationString+" of type "+info2.tpe+
- (if (isView) "\n are possible conversion functions from "+ pt.typeArgs(0)+" to "+pt.typeArgs(1)
+ "ambiguous implicit value:\n "+
+ pre1+" "+info1.sym+info1.sym.locationString+" of type "+info1.tpe+"\n "+
+ pre2+" "+info2.sym+info2.sym.locationString+" of type "+info2.tpe+"\n "+
+ trailer+
+ (if (isView) "are possible conversion functions from "+ pt.typeArgs(0)+" to "+pt.typeArgs(1)
else "\n match expected type "+pt))
/** Search list of implicit info lists for one matching prototype
@@ -2405,15 +2407,13 @@ trait Typers requires Analyzer {
* @return ...
*/
def searchImplicit(implicitInfoss: List[List[ImplicitInfo]], isLocal: boolean): Tree = {
- def isSubClassOrObject(sym1: Symbol, sym2: Symbol) = {
- (sym1 isSubClass sym2) ||
- sym1.isModuleClass && sym2.isModuleClass &&
- (sym1.linkedClassOfClass isSubClass sym2.linkedClassOfClass)
- }
+ def isSubClassOrObject(sym1: Symbol, sym2: Symbol): boolean =
+ sym1 != NoSymbol && (sym1 isSubClass sym2) ||
+ sym1.isModuleClass && isSubClassOrObject(sym1.linkedClassOfClass, sym2) ||
+ sym2.isModuleClass && isSubClassOrObject(sym1, sym2.linkedClassOfClass)
def improves(info1: ImplicitInfo, info2: ImplicitInfo) =
(info2 == NoImplicitInfo) ||
(info1 != NoImplicitInfo) &&
- isSubClassOrObject(info1.sym.owner, info2.sym.owner) &&
isStrictlyBetter(info1.tpe, info2.tpe)
val shadowed = new HashSet[Name](8)
def isApplicable(info: ImplicitInfo): boolean =
@@ -2429,10 +2429,17 @@ trait Typers requires Analyzer {
}
val applicable = List.flatten(implicitInfoss map applicableInfos)
val best = (NoImplicitInfo /: applicable) ((best, alt) => if (improves(alt, best)) alt else best)
- val competing = applicable dropWhile (alt => best == alt || improves(best, alt))
if (best == NoImplicitInfo) EmptyTree
else {
- if (!competing.isEmpty) ambiguousError(best, competing.head)
+ val competing = applicable dropWhile (alt => best == alt || improves(best, alt))
+ if (!competing.isEmpty) ambiguousError(best, competing.head, "both", "and ", "")
+ for (val alt <- applicable)
+ if (alt.sym.owner != best.sym.owner && isSubClassOrObject(alt.sym.owner, best.sym.owner)) {
+ ambiguousError(best, alt,
+ "most specific definition is:",
+ "yet alternative definition ",
+ "is defined in a subclass.\n Both definitions ")
+ }
tc.typedImplicit(pos, best, pt, isLocal)
}
}