diff options
author | Paul Phillips <paulp@improving.org> | 2011-12-08 15:31:07 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-12-08 15:31:07 -0800 |
commit | a8da940cb62d7a57ef4d405a176223c02479c779 (patch) | |
tree | ee59f60a956f52e102b69009f1bda03e61937aaa /src/compiler | |
parent | 4da259b26eb9d3409392fef91d36471cd7ac4354 (diff) | |
parent | 6a16e1a4fc08fd47b19c32c19106e6405160e1c4 (diff) | |
download | scala-a8da940cb62d7a57ef4d405a176223c02479c779.tar.gz scala-a8da940cb62d7a57ef4d405a176223c02479c779.tar.bz2 scala-a8da940cb62d7a57ef4d405a176223c02479c779.zip |
Merge remote-tracking branches 'VladUreche/issue/5054' and 'jsuereth/dont_resolve_releases'
Diffstat (limited to 'src/compiler')
14 files changed, 48 insertions, 27 deletions
diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index a59ea2c1bf..75fd733e7e 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -494,8 +494,8 @@ trait Symbols extends api.Symbols { self: SymbolTable => // string. So this needs attention. For now the fact that migration is // private[scala] ought to provide enough protection. def hasMigrationAnnotation = hasAnnotation(MigrationAnnotationClass) - def migrationMessage = getAnnotation(MigrationAnnotationClass) flatMap { _.stringArg(2) } - def migrationVersion = getAnnotation(MigrationAnnotationClass) map { version => version.intArg(0).get + "." + version.intArg(1).get } + def migrationMessage = getAnnotation(MigrationAnnotationClass) flatMap { _.stringArg(0) } + def migrationVersion = getAnnotation(MigrationAnnotationClass) flatMap { _.stringArg(1) } def elisionLevel = getAnnotation(ElidableMethodClass) flatMap { _.intArg(0) } def implicitNotFoundMsg = getAnnotation(ImplicitNotFoundClass) flatMap { _.stringArg(0) } diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 265261f594..d17747e22a 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -649,7 +649,11 @@ trait Types extends api.Types { self: SymbolTable => } /** Returns all parts of this type which satisfy predicate `p` */ - def filter(p: Type => Boolean): List[Type] = new FilterTypeCollector(p).collect(this).toList + def filter(p: Type => Boolean): List[Type] = new FilterTypeCollector(p) collect this + def withFilter(p: Type => Boolean) = new FilterTypeCollector(p) { + def foreach[U](f: Type => U): Unit = collect(Type.this) foreach f + def map[T](f: Type => T): List[T] = collect(Type.this) map f + } /** Returns optionally first type (in a preorder traversal) which satisfies predicate `p`, * or None if none exists. @@ -4094,9 +4098,13 @@ A type's typeSymbol should never be inspected directly. } /** A map to implement the `filter` method. */ - class FilterTypeCollector(p: Type => Boolean) extends TypeCollector(new ListBuffer[Type]) { + class FilterTypeCollector(p: Type => Boolean) extends TypeCollector[List[Type]](Nil) { + def withFilter(q: Type => Boolean) = new FilterTypeCollector(tp => p(tp) && q(tp)) + + override def collect(tp: Type) = super.collect(tp).reverse + def traverse(tp: Type) { - if (p(tp)) result += tp + if (p(tp)) result ::= tp mapOver(tp) } } diff --git a/src/compiler/scala/reflect/internal/pickling/UnPickler.scala b/src/compiler/scala/reflect/internal/pickling/UnPickler.scala index 9aa3d8a2c3..1a8540c158 100644 --- a/src/compiler/scala/reflect/internal/pickling/UnPickler.scala +++ b/src/compiler/scala/reflect/internal/pickling/UnPickler.scala @@ -46,7 +46,7 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ { } } - class Scan(bytes: Array[Byte], offset: Int, classRoot: Symbol, moduleRoot: Symbol, filename: String) extends PickleBuffer(bytes, offset, -1) { + class Scan(_bytes: Array[Byte], offset: Int, classRoot: Symbol, moduleRoot: Symbol, filename: String) extends PickleBuffer(_bytes, offset, -1) { //println("unpickle " + classRoot + " and " + moduleRoot)//debug protected def debug = settings.debug.value diff --git a/src/compiler/scala/reflect/runtime/ToolBoxes.scala b/src/compiler/scala/reflect/runtime/ToolBoxes.scala index e617239398..03947574db 100644 --- a/src/compiler/scala/reflect/runtime/ToolBoxes.scala +++ b/src/compiler/scala/reflect/runtime/ToolBoxes.scala @@ -42,11 +42,10 @@ trait ToolBoxes extends { self: Universe => def wrapInObject(expr: Tree, fvs: List[Symbol]): ModuleDef = { val obj = EmptyPackageClass.newModule(NoPosition, nextWrapperModuleName()) - val minfo = ClassInfoType(List(ObjectClass.tpe), new Scope, obj.moduleClass) + val minfo = ClassInfoType(List(ObjectClass.tpe, ScalaObjectClass.tpe), new Scope, obj.moduleClass) obj.moduleClass setInfo minfo obj setInfo obj.moduleClass.tpe val meth = obj.moduleClass.newMethod(NoPosition, wrapperMethodName) - meth setFlag Flags.STATIC def makeParam(fv: Symbol) = meth.newValueParameter(NoPosition, fv.name) setInfo fv.tpe meth setInfo MethodType(fvs map makeParam, expr.tpe) minfo.decls enter meth @@ -88,11 +87,19 @@ trait ToolBoxes extends { self: Universe => def runExpr(expr: Tree): Any = { val etpe = expr.tpe val fvs = (expr filter isFree map (_.symbol)).distinct + + reporter.reset() val className = compileExpr(expr, fvs) + if (reporter.hasErrors) { + throw new Error("reflective compilation has failed") + } + if (settings.debug.value) println("generated: "+className) val jclazz = jClass.forName(moduleFileName(className), true, classLoader) val jmeth = jclazz.getDeclaredMethods.find(_.getName == wrapperMethodName).get - val result = jmeth.invoke(null, fvs map (sym => sym.asInstanceOf[FreeVar].value.asInstanceOf[AnyRef]): _*) + val jfield = jclazz.getDeclaredFields.find(_.getName == NameTransformer.MODULE_INSTANCE_NAME).get + val singleton = jfield.get(null) + val result = jmeth.invoke(singleton, fvs map (sym => sym.asInstanceOf[FreeVar].value.asInstanceOf[AnyRef]): _*) if (etpe.typeSymbol != FunctionClass(0)) result else { val applyMeth = result.getClass.getMethod("apply") diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index 7fea76c7b1..f900859f46 100644 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -22,8 +22,8 @@ import symtab.Flags.{ACCESSOR, PARAMACCESSOR} /** The main class of the presentation compiler in an interactive environment such as an IDE */ -class Global(settings: Settings, reporter: Reporter, projectName: String = "") - extends scala.tools.nsc.Global(settings, reporter) +class Global(settings: Settings, _reporter: Reporter, projectName: String = "") + extends scala.tools.nsc.Global(settings, _reporter) with CompilerControl with RangePositions with ContextTrees diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index d001a0af8b..98345dd01e 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -297,7 +297,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL { case nme.toDouble => "toDouble" case _ => return None } - Some(newName, runtimeTest) + Some((newName, runtimeTest)) } def infixTest(name: Name): Option[(String, Tree => Tree)] = { val (newName, runtimeTest) = name match { @@ -322,7 +322,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL { case nme.ZAND => ("takeConditionalAnd", testForBoolean) case _ => return None } - Some(newName, runtimeTest) + Some((newName, runtimeTest)) } /** The Tree => Tree function in the return is necessary to prevent the original qual diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 9806857ff2..1a421eb82f 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -421,7 +421,7 @@ abstract class Erasure extends AddInterfaces */ /** The modifier typer which retypes with erased types. */ - class Eraser(context: Context) extends Typer(context) { + class Eraser(_context: Context) extends Typer(_context) { private def safeToRemoveUnbox(cls: Symbol): Boolean = (cls == definitions.NullClass) || isBoxedValueClass(cls) diff --git a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala index 031be21f24..2bed5bffd4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala @@ -69,7 +69,7 @@ abstract class Duplicators extends Analyzer { * tree, except for TypeTrees, are erased prior to type checking. TypeTrees * are fixed by substituting invalid symbols for the new ones. */ - class BodyDuplicator(context: Context) extends Typer(context: Context) { + class BodyDuplicator(_context: Context) extends Typer(_context) { class FixInvalidSyms extends TypeMap { diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 79db9ab000..5b38ddd092 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1311,7 +1311,11 @@ trait Infer { case TypeRef(_, sym, _) if isLocalBinding(sym) => ; case _ => - patternWarning(arg, "non variable type-argument ") + // Want to warn about type arguments, not type parameters. Otherwise we'll + // see warnings about "invisible" types, like: val List(x0) = x1 leading to "non + // variable type-argument A in type pattern List[A]..." + if (!arg.typeSymbol.isTypeParameterOrSkolem) + patternWarning(arg, "non variable type-argument ") } } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 0f57285480..364e887939 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -422,7 +422,7 @@ trait Namers extends MethodSynthesis { * @return the companion object symbol. */ def ensureCompanionObject(cdef: ClassDef, creator: ClassDef => Tree = companionModuleDef(_)): Symbol = { - val m = companionModuleOf(cdef.symbol, context) + val m = companionSymbolOf(cdef.symbol, context) // @luc: not sure why "currentRun.compiles(m)" is needed, things breaks // otherwise. documentation welcome. // @@ -855,7 +855,7 @@ trait Namers extends MethodSynthesis { // @check: this seems to work only if the type completer of the class runs before the one of the // module class: the one from the module class removes the entry from classOfModuleClass (see above). if (clazz.isClass && !clazz.hasModuleFlag) { - val modClass = companionModuleOf(clazz, context).moduleClass + val modClass = companionSymbolOf(clazz, context).moduleClass Namers.this.classOfModuleClass get modClass map { cdefRef => val cdef = cdefRef() @@ -1082,7 +1082,7 @@ trait Namers extends MethodSynthesis { val parentNamer = if (isConstr) { val (cdef, nmr) = moduleNamer.getOrElse { - val module = companionModuleOf(clazz, context) + val module = companionSymbolOf(clazz, context) module.initialize // call type completer (typedTemplate), adds the // module's templateNamer to classAndNamerOfModule classAndNamerOfModule get module match { diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index e4ebe13217..8611fafe52 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -189,7 +189,7 @@ trait NamesDefaults { self: Analyzer => if (pre == NoType) { None } else { - val module = companionModuleOf(baseFun.symbol.owner, context) + val module = companionSymbolOf(baseFun.symbol.owner, context) if (module == NoSymbol) None else { val ref = atPos(pos.focus)(gen.mkAttributedRef(pre, module)) @@ -414,7 +414,7 @@ trait NamesDefaults { self: Analyzer => if (i > 0) { val defGetterName = nme.defaultGetterName(param.owner.name, i) if (param.owner.isConstructor) { - val mod = companionModuleOf(param.owner.owner, context) + val mod = companionSymbolOf(param.owner.owner, context) mod.info.member(defGetterName) } else { diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 645d3ecfa0..98f1c96cad 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1273,8 +1273,10 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R * indicating it has changed semantics between versions. */ private def checkMigration(sym: Symbol, pos: Position) = { - for (msg <- sym.migrationMessage) - unit.warning(pos, sym.fullLocationString + " has changed semantics:\n" + msg) + if (sym.hasMigrationAnnotation) + unit.warning(pos, "%s has changed semantics in version %s:\n%s".format( + sym.fullLocationString, sym.migrationVersion.get, sym.migrationMessage.get) + ) } private def lessAccessible(otherSym: Symbol, memberSym: Symbol): Boolean = ( diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 7671ccbed7..9b03d59216 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1361,7 +1361,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { "you want, you must write the annotation class in Java.") if (!isPastTyper) { for (ann <- clazz.getAnnotation(DeprecatedAttr)) { - val m = companionModuleOf(clazz, context) + val m = companionSymbolOf(clazz, context) if (m != NoSymbol) m.moduleClass.addAnnotation(AnnotationInfo(ann.atp, ann.args, List())) } @@ -1377,7 +1377,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { def typedModuleDef(mdef: ModuleDef): Tree = { // 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 = companionClassOf(mdef.symbol, context) + val linkedClass = companionSymbolOf(mdef.symbol, context) if (linkedClass != NoSymbol) linkedClass.info.decl(nme.CONSTRUCTOR).alternatives foreach (_.initialize) @@ -2223,7 +2223,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { (methCtx != NoContext) && { val contextFun = methCtx.tree.symbol contextFun.isPrimaryConstructor && contextFun.owner.isModuleClass && - companionModuleOf(calledFun.owner, context).moduleClass == contextFun.owner + companionSymbolOf(calledFun.owner, context).moduleClass == contextFun.owner } } } diff --git a/src/compiler/scala/tools/util/EditDistance.scala b/src/compiler/scala/tools/util/EditDistance.scala index a8d7408532..b705a1eac4 100644 --- a/src/compiler/scala/tools/util/EditDistance.scala +++ b/src/compiler/scala/tools/util/EditDistance.scala @@ -33,7 +33,7 @@ object EditDistance { 0 to n foreach (x => d(x)(0) = x) 0 to m foreach (x => d(0)(x) = x) - for (i <- 1 to n ; val s_i = s(i - 1) ; j <- 1 to m) { + for (i <- 1 to n ; s_i = s(i - 1) ; j <- 1 to m) { val t_j = t(j - 1) val cost = if (s_i == t_j) 0 else 1 |