From 9e88ddf82e2d8aa779aab46aec284d5566deac14 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 12 Dec 2012 16:05:24 -0800 Subject: Eliminating var-like setter tpe_= on Tree. Deprecated tpe_= on Tree, which is redundant with and less useful than setType. To provide a small layer of insulation from the direct nulling out of mutable fields used to signal the typer, added def clearType() which is merely tree.tpe = null but is shamefaced about the null and var-settings parts like a respectable method should be. --- src/compiler/scala/tools/nsc/ast/Trees.scala | 7 ++-- .../scala/tools/nsc/backend/icode/GenICode.scala | 4 +-- .../scala/tools/nsc/transform/Erasure.scala | 12 +++---- src/compiler/scala/tools/nsc/transform/Mixin.scala | 17 +++++---- .../tools/nsc/transform/SpecializeTypes.scala | 11 +++--- .../tools/nsc/typechecker/ContextErrors.scala | 4 +-- .../scala/tools/nsc/typechecker/Contexts.scala | 4 +-- .../scala/tools/nsc/typechecker/Duplicators.scala | 33 +++++++---------- .../scala/tools/nsc/typechecker/EtaExpansion.scala | 6 ++-- .../scala/tools/nsc/typechecker/Namers.scala | 3 +- .../scala/tools/nsc/typechecker/TreeCheckers.scala | 9 ++--- .../scala/tools/nsc/typechecker/Typers.scala | 42 +++++++++++----------- .../tools/selectivecps/SelectiveANFTransform.scala | 2 +- .../tools/selectivecps/SelectiveCPSTransform.scala | 6 ++-- src/reflect/scala/reflect/internal/Importers.scala | 2 +- src/reflect/scala/reflect/internal/Symbols.scala | 4 +-- src/reflect/scala/reflect/internal/TreeGen.scala | 6 ++-- src/reflect/scala/reflect/internal/Trees.scala | 11 +++--- src/reflect/scala/reflect/macros/Universe.scala | 4 +-- 19 files changed, 85 insertions(+), 102 deletions(-) diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 0e3e2fe644..4b5e23e177 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -343,9 +343,7 @@ trait Trees extends scala.reflect.internal.Trees { self: Global => if (tpt.original != null) transform(tpt.original) else if (tpt.tpe != null && (tpt.wasEmpty || (tpt.tpe exists (tp => locals contains tp.typeSymbol)))) { - val dupl = tpt.duplicate - dupl.tpe = null - dupl + tpt.duplicate.clearType() } else tree case TypeApply(fn, args) if args map transform exists (_.isEmpty) => @@ -356,8 +354,7 @@ trait Trees extends scala.reflect.internal.Trees { self: Global => val dupl = tree.duplicate if (tree.hasSymbolField && (!localOnly || (locals contains tree.symbol)) && !(keepLabels && tree.symbol.isLabel)) dupl.symbol = NoSymbol - dupl.tpe = null - dupl + dupl.clearType() } } } diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index cc3562079e..2ea26ddaa9 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -1643,9 +1643,7 @@ abstract class GenICode extends SubComponent { t match { case t @ Apply(_, args) if sym.isLabel && !boundLabels(sym) => val newSym = getLabel(sym.pos, sym.name) - val tree = Apply(global.gen.mkAttributedRef(newSym), transformTrees(args)) setPos t.pos - tree.tpe = t.tpe - tree + Apply(global.gen.mkAttributedRef(newSym), transformTrees(args)) setPos t.pos setType t.tpe case t @ LabelDef(name, params, rhs) => val newSym = getLabel(t.pos, name) diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 45bd5cf003..13d3bb23cb 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -857,8 +857,7 @@ abstract class Erasure extends AddInterfaces alt => alt == first || !(first.tpe looselyMatches alt.tpe) } if (tree.symbol ne sym1) { - tree1.symbol = sym1 - tree1.tpe = sym1.tpe + tree1 setSymbol sym1 setType sym1.tpe } } tree1 @@ -1260,13 +1259,12 @@ abstract class Erasure extends AddInterfaces tree1 setType specialScalaErasure(tree1.tpe) case ArrayValue(elemtpt, trees) => treeCopy.ArrayValue( - tree1, elemtpt setType specialScalaErasure.applyInArray(elemtpt.tpe), trees map transform) setType null + tree1, elemtpt setType specialScalaErasure.applyInArray(elemtpt.tpe), trees map transform).clearType() case DefDef(_, _, _, _, tpt, _) => - val result = super.transform(tree1) setType null - tpt.tpe = specialErasure(tree1.symbol)(tree1.symbol.tpe).resultType - result + try super.transform(tree1).clearType() + finally tpt setType specialErasure(tree1.symbol)(tree1.symbol.tpe).resultType case _ => - super.transform(tree1) setType null + super.transform(tree1).clearType() } } } diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index 45ef083b66..0769b67282 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -396,8 +396,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { } sourceModule setInfo sym.tpe // Companion module isn't visible for anonymous class at this point anyway - assert(clazz.sourceModule != NoSymbol || clazz.isAnonymousClass, - clazz + " has no sourceModule: sym = " + sym + " sym.tpe = " + sym.tpe) + assert(clazz.sourceModule != NoSymbol || clazz.isAnonymousClass, s"$clazz has no sourceModule: $sym ${sym.tpe}") parents1 = List() decls1 = newScopeWith(decls.toList filter isImplementedStatically: _*) } else if (!parents.isEmpty) { @@ -545,12 +544,18 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { } tree } + // !!! What is this doing, and why is it only looking for exactly + // one type parameter? It would seem to be + // "Map implementation class types in type-apply's to their interfaces" + // from the comment on preTransform, but is there some way we should know + // that impl class types in type applies can only appear in single + // type parameter type constructors? case Apply(tapp @ TypeApply(fn, List(arg)), List()) => if (arg.tpe.typeSymbol.isImplClass) { val ifacetpe = toInterface(arg.tpe) - arg.tpe = ifacetpe - tapp.tpe = MethodType(List(), ifacetpe) - tree.tpe = ifacetpe + arg setType ifacetpe + tapp setType MethodType(Nil, ifacetpe) + tree setType ifacetpe } tree case ValDef(_, _, _, _) if currentOwner.isImplClass => @@ -1129,7 +1134,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { // change every node type that refers to an implementation class to its // corresponding interface, unless the node's symbol is an implementation class. if (tree.tpe.typeSymbol.isImplClass && ((sym eq null) || !sym.isImplClass)) - tree.tpe = toInterface(tree.tpe) + tree modifyType toInterface tree match { case templ @ Template(parents, self, body) => diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index 4e4c1b98ac..8e274f7647 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -1240,9 +1240,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { class BodyDuplicator(_context: Context) extends super.BodyDuplicator(_context) { override def castType(tree: Tree, pt: Type): Tree = { - // log(" expected type: " + pt) - // log(" tree type: " + tree.tpe) - tree.tpe = if (tree.tpe != null) fixType(tree.tpe) else null + tree modifyType fixType // log(" tree type: " + tree.tpe) val ntree = if (tree.tpe != null && !(tree.tpe <:< pt)) { val casttpe = CastMap(tree.tpe) @@ -1250,8 +1248,8 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { else if (casttpe <:< CastMap(pt)) gen.mkCast(tree, pt) else tree } else tree - ntree.tpe = null - ntree + + ntree.clearType() } } @@ -1679,8 +1677,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { false) // don't make private fields public val newBody = symSubstituter(body(source).duplicate) - tpt.tpe = tpt.tpe.substSym(oldtparams, newtparams) - + tpt modifyType (_.substSym(oldtparams, newtparams)) copyDefDef(tree)(vparamss = List(newSyms map ValDef), rhs = newBody) } diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index 30c12a4286..fe93a0ea76 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -154,7 +154,7 @@ trait ContextErrors { // the found/req types. val foundType: Type = req.normalize match { case RefinedType(parents, decls) if !decls.isEmpty && found.typeSymbol.isAnonOrRefinementClass => - val retyped = typed (tree.duplicate setType null) + val retyped = typed (tree.duplicate.clearType()) val foundDecls = retyped.tpe.decls filter (sym => !sym.isConstructor && !sym.isSynthetic) if (foundDecls.isEmpty || (found.typeSymbol eq NoSymbol)) found else { @@ -182,7 +182,7 @@ trait ContextErrors { } def ParentTypesError(templ: Template, ex: TypeError) = { - templ.tpe = null + templ.clearType() issueNormalTypeError(templ, ex.getMessage()) setError(templ) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index c0d2f44c7b..9ee0855bc6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -106,8 +106,8 @@ trait Contexts { self: Analyzer => var sc = startContext while (sc != NoContext) { sc.tree match { - case Import(qual, _) => qual.tpe = singleType(qual.symbol.owner.thisType, qual.symbol) - case _ => + case Import(qual, _) => qual setType singleType(qual.symbol.owner.thisType, qual.symbol) + case _ => } sc = sc.outer } diff --git a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala index 9c23b8663c..1c48eeed70 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala @@ -210,40 +210,35 @@ abstract class Duplicators extends Analyzer { tree match { case ttree @ TypeTree() => // log("fixing tpe: " + tree.tpe + " with sym: " + tree.tpe.typeSymbol) - ttree.tpe = fixType(ttree.tpe) - ttree + ttree modifyType fixType case Block(stats, res) => debuglog("invalidating block") invalidateAll(stats) invalidate(res) - tree.tpe = null - super.typed(tree, mode, pt) + super.typed(tree.clearType(), mode, pt) case ClassDef(_, _, _, tmpl @ Template(parents, _, stats)) => // log("invalidating classdef " + tree) tmpl.symbol = tree.symbol.newLocalDummy(tree.pos) invalidateAll(stats, tree.symbol) - tree.tpe = null - super.typed(tree, mode, pt) + super.typed(tree.clearType(), mode, pt) case ddef @ DefDef(_, _, _, _, tpt, rhs) => - ddef.tpt.tpe = fixType(ddef.tpt.tpe) - ddef.tpe = null - super.typed(ddef, mode, pt) + ddef.tpt modifyType fixType + super.typed(ddef.clearType(), mode, pt) case vdef @ ValDef(mods, name, tpt, rhs) => // log("vdef fixing tpe: " + tree.tpe + " with sym: " + tree.tpe.typeSymbol + " and " + invalidSyms) //if (mods.hasFlag(Flags.LAZY)) vdef.symbol.resetFlag(Flags.MUTABLE) // Martin to Iulian: lazy vars can now appear because they are no longer boxed; Please check that deleting this statement is OK. - vdef.tpt.tpe = fixType(vdef.tpt.tpe) - vdef.tpe = null - super.typed(vdef, mode, pt) + vdef.tpt modifyType fixType + super.typed(vdef.clearType(), mode, pt) case ldef @ LabelDef(name, params, rhs) => // log("label def: " + ldef) // in case the rhs contains any definitions -- TODO: is this necessary? invalidate(rhs) - ldef.tpe = null + ldef.clearType() // is this LabelDef generated by tailcalls? val isTailLabel = (ldef.params.length >= 1) && (ldef.params.head.name == nme.THIS) @@ -261,27 +256,23 @@ abstract class Duplicators extends Analyzer { val params1 = params map newParam val rhs1 = (new TreeSubstituter(params map (_.symbol), params1) transform rhs) // TODO: duplicate? - rhs1.tpe = null - super.typed(treeCopy.LabelDef(tree, name, params1, rhs1), mode, pt) + super.typed(treeCopy.LabelDef(tree, name, params1, rhs1.clearType()), mode, pt) case Bind(name, _) => // log("bind: " + tree) invalidate(tree) - tree.tpe = null - super.typed(tree, mode, pt) + super.typed(tree.clearType(), mode, pt) case Ident(_) if tree.symbol.isLabel => debuglog("Ident to labeldef " + tree + " switched to ") tree.symbol = updateSym(tree.symbol) - tree.tpe = null - super.typed(tree, mode, pt) + super.typed(tree.clearType(), mode, pt) case Ident(_) if (origtreesym ne null) && origtreesym.isLazy => debuglog("Ident to a lazy val " + tree + ", " + tree.symbol + " updated to " + origtreesym) tree.symbol = updateSym(origtreesym) - tree.tpe = null - super.typed(tree, mode, pt) + super.typed(tree.clearType(), mode, pt) case Select(th @ This(_), sel) if (oldClassOwner ne null) && (th.symbol == oldClassOwner) => // We use the symbol name instead of the tree name because the symbol diff --git a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala index 2806d7b2d9..4fbb788c7b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala +++ b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala @@ -94,11 +94,11 @@ trait EtaExpansion { self: Analyzer => // with repeated params, there might be more or fewer args than params liftout(arg, byName(i).getOrElse(false)) } - treeCopy.Apply(tree, liftoutPrefix(fn), newArgs) setType null + treeCopy.Apply(tree, liftoutPrefix(fn), newArgs).clearType() case TypeApply(fn, args) => - treeCopy.TypeApply(tree, liftoutPrefix(fn), args) setType null + treeCopy.TypeApply(tree, liftoutPrefix(fn), args).clearType() case Select(qual, name) => - treeCopy.Select(tree, liftout(qual, false), name) setSymbol NoSymbol setType null + treeCopy.Select(tree, liftout(qual, false), name).clearType() setSymbol NoSymbol case Ident(name) => tree } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 9a32747c3a..d524c88f43 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1361,8 +1361,7 @@ trait Namers extends MethodSynthesis { transformed(tree) = newImport // copy symbol and type attributes back into old expression // so that the structure builder will find it. - expr.symbol = expr1.symbol - expr.tpe = expr1.tpe + expr setSymbol expr1.symbol setType expr1.tpe ImportType(expr1) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala index fb95c952d2..260bd87fdf 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala @@ -192,11 +192,8 @@ abstract class TreeCheckers extends Analyzer { override def typed(tree: Tree, mode: Int, pt: Type): Tree = returning(tree) { case EmptyTree | TypeTree() => () case _ if tree.tpe != null => - tpeOfTree.getOrElseUpdate(tree, { - val saved = tree.tpe - tree.tpe = null - saved - }) + tpeOfTree.getOrElseUpdate(tree, try tree.tpe finally tree.clearType()) + wrap(tree)(super.typed(tree, mode, pt) match { case _: Literal => () case x if x ne tree => treesDiffer(tree, x) @@ -288,7 +285,7 @@ abstract class TreeCheckers extends Analyzer { if (oldtpe =:= tree.tpe) () else typesDiffer(tree, oldtpe, tree.tpe) - tree.tpe = oldtpe + tree setType oldtpe super.traverse(tree) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index a1c1b53cce..f243569dc8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -53,7 +53,7 @@ trait Typers extends Modes with Adaptations with Tags { object UnTyper extends Traverser { override def traverse(tree: Tree) = { if (tree.canHaveAttrs) { - tree.tpe = null + tree.clearType() if (tree.hasSymbolField) tree.symbol = NoSymbol } super.traverse(tree) @@ -323,7 +323,7 @@ trait Typers extends Modes with Adaptations with Tags { def checkNonCyclic(defn: Tree, tpt: Tree) { if (!checkNonCyclic(defn.pos, tpt.tpe, defn.symbol)) { - tpt.tpe = ErrorType + tpt setType ErrorType defn.symbol.setInfo(ErrorType) } } @@ -813,7 +813,7 @@ trait Typers extends Modes with Adaptations with Tags { val tree1 = typed(resetAllAttrs(original), mode, WildcardType) // Q: `typed` already calls `addAnnotations` and `adapt`. the only difference here is that // we pass `EmptyTree` as the `original`. intended? added in 2009 (53d98e7d42) by martin. - tree1.tpe = addAnnotations(tree1, tree1.tpe) + tree1 setType addAnnotations(tree1, tree1.tpe) if (tree1.isEmpty) tree1 else adapt(tree1, mode, pt, EmptyTree) } ) @@ -931,7 +931,7 @@ trait Typers extends Modes with Adaptations with Tags { tree setSymbol overloadedExtractorOfObject tree.tpe match { - case OverloadedType(pre, alts) => tree.tpe = overloadedType(pre, alts filter (alt => hasUnapplyMember(alt.tpe))) + case OverloadedType(pre, alts) => tree setType overloadedType(pre, alts filter (alt => hasUnapplyMember(alt.tpe))) case _ => } val unapply = unapplyMember(extractor.tpe) @@ -1584,7 +1584,7 @@ trait Typers extends Modes with Adaptations with Tags { if (preSuperVals.isEmpty && preSuperStats.nonEmpty) devWarning("Wanted to zip empty presuper val list with " + preSuperStats) else - map2(preSuperStats, preSuperVals)((ldef, gdef) => gdef.tpt.tpe = ldef.symbol.tpe) + map2(preSuperStats, preSuperVals)((ldef, gdef) => gdef.tpt setType ldef.symbol.tpe) if (superCall1 == cunit) EmptyTree else cbody2 case _ => @@ -1604,7 +1604,7 @@ trait Typers extends Modes with Adaptations with Tags { return explode(supersupertpt, supertpt1 :: acc) } } - if (supertpt.tpe.typeSymbol == AnyClass) supertpt.tpe = AnyRefClass.tpe + if (supertpt.tpe.typeSymbol == AnyClass) supertpt setType AnyRefClass.tpe supertpt :: acc } explode(first, Nil) ++ rest @@ -2278,7 +2278,7 @@ trait Typers extends Modes with Adaptations with Tags { if (!nme.isLoopHeaderLabel(ldef.symbol.name) || isPastTyper) { val restpe = ldef.symbol.tpe.resultType val rhs1 = typed(ldef.rhs, restpe) - ldef.params foreach (param => param.tpe = param.symbol.tpe) + ldef.params foreach (param => param setType param.symbol.tpe) deriveLabelDef(ldef)(_ => rhs1) setType restpe } else { @@ -2286,14 +2286,14 @@ trait Typers extends Modes with Adaptations with Tags { val rhs1 = typed(ldef.rhs) val restpe = rhs1.tpe if (restpe == initpe) { // stable result, no need to check again - ldef.params foreach (param => param.tpe = param.symbol.tpe) + ldef.params foreach (param => param setType param.symbol.tpe) treeCopy.LabelDef(ldef, ldef.name, ldef.params, rhs1) setType restpe } else { context.scope.unlink(ldef.symbol) val sym2 = namer.enterInScope( context.owner.newLabel(ldef.name, ldef.pos) setInfo MethodType(List(), restpe)) val rhs2 = typed(resetAllAttrs(ldef.rhs), restpe) - ldef.params foreach (param => param.tpe = param.symbol.tpe) + ldef.params foreach (param => param setType param.symbol.tpe) deriveLabelDef(ldef)(_ => rhs2) setSymbol sym2 setType restpe } } @@ -2399,7 +2399,7 @@ trait Typers extends Modes with Adaptations with Tags { val contextWithTypeBounds = context.nextEnclosing(_.tree.isInstanceOf[CaseDef]) if (contextWithTypeBounds.savedTypeBounds.nonEmpty) { - body1.tpe = contextWithTypeBounds restoreTypeBounds body1.tpe + body1 modifyType (contextWithTypeBounds restoreTypeBounds _) // insert a cast if something typechecked under the GADT constraints, // but not in real life (i.e., now that's we've reset the method's type skolems' @@ -3276,7 +3276,7 @@ trait Typers extends Modes with Adaptations with Tags { else None if (!isApplicableSafe(Nil, unappType, List(pt), WildcardType)) { - //Console.println("UNAPP: need to typetest, arg.tpe = "+arg.tpe+", unappType = "+unappType) + //Console.println(s"UNAPP: need to typetest, arg: ${arg.tpe} unappType: $unappType") val (freeVars, unappFormal) = freshArgType(unappType.skolemizeExistential(context.owner, tree)) val unapplyContext = context.makeNewScope(context.tree, context.owner) freeVars foreach unapplyContext.scope.enter @@ -3286,12 +3286,12 @@ trait Typers extends Modes with Adaptations with Tags { // turn any unresolved type variables in freevars into existential skolems val skolems = freeVars map (fv => unapplyContext.owner.newExistentialSkolem(fv, fv)) - arg.tpe = pattp.substSym(freeVars, skolems) + arg setType pattp.substSym(freeVars, skolems) argDummy setInfo arg.tpe } - // setType null is necessary so that ref will be stabilized; see bug 881 - val fun1 = typedPos(fun.pos)(Apply(Select(fun setType null, unapp), List(arg))) + // clearing the type is necessary so that ref will be stabilized; see bug 881 + val fun1 = typedPos(fun.pos)(Apply(Select(fun.clearType(), unapp), List(arg))) if (fun1.tpe.isErroneous) duplErrTree else { @@ -3305,7 +3305,7 @@ trait Typers extends Modes with Adaptations with Tags { val pt1 = if (isFullyDefined(pt)) pt else makeFullyDefined(pt) // SI-1048 val itype = glb(List(pt1, arg.tpe)) - arg.tpe = pt1 // restore type (arg is a dummy tree, just needs to pass typechecking) + arg setType pt1 // restore type (arg is a dummy tree, just needs to pass typechecking) val unapply = UnApply(fun1, args1) setPos tree.pos setType itype // if the type that the unapply method expects for its argument is uncheckable, wrap in classtag extractor @@ -4018,7 +4018,7 @@ trait Typers extends Modes with Adaptations with Tags { // Erroneous annotations were already reported in typedAnnotation arg1 // simply drop erroneous annotations else { - ann.tpe = atype + ann setType atype resultingTypeTree(atype) } } else { @@ -4029,7 +4029,7 @@ trait Typers extends Modes with Adaptations with Tags { else { if (ann.tpe == null) { val annotInfo = typedAnnotation(ann, annotMode) - ann.tpe = arg1.tpe.withAnnotation(annotInfo) + ann setType arg1.tpe.withAnnotation(annotInfo) } val atype = ann.tpe Typed(arg1, resultingTypeTree(atype)) setPos tree.pos setType atype @@ -4580,7 +4580,7 @@ trait Typers extends Modes with Adaptations with Tags { NoSymbol } if (phase.erasedTypes && qual.isInstanceOf[Super] && tree.symbol != NoSymbol) - qual.tpe = tree.symbol.owner.tpe + qual setType tree.symbol.owner.tpe if (!reallyExists(sym)) { def handleMissing: Tree = { @@ -5176,7 +5176,7 @@ trait Typers extends Modes with Adaptations with Tags { try { if (context.retyping && (tree.tpe ne null) && (tree.tpe.isErroneous || !(tree.tpe <:< pt))) { - tree.tpe = null + tree.clearType() if (tree.hasSymbolField) tree.symbol = NoSymbol } @@ -5200,7 +5200,7 @@ trait Typers extends Modes with Adaptations with Tags { tree1 } - tree1.tpe = addAnnotations(tree1, tree1.tpe) + tree1 modifyType (addAnnotations(tree1, _)) val result = if (tree1.isEmpty) tree1 else adapt(tree1, mode, pt, tree) if (!alreadyTyped) { @@ -5212,7 +5212,7 @@ trait Typers extends Modes with Adaptations with Tags { result } catch { case ex: TypeError => - tree.tpe = null + tree.clearType() // The only problematic case are (recoverable) cyclic reference errors which can pop up almost anywhere. printTyping("caught %s: while typing %s".format(ex, tree)) //DEBUG diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala index f62eebaaa0..5775c662da 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala @@ -128,7 +128,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with def transformPureMatch(tree: Tree, selector: Tree, cases: List[CaseDef]) = { val caseVals = cases map { case cd @ CaseDef(pat, guard, body) => - // if (!hasPlusMarker(body.tpe)) body.tpe = body.tpe withAnnotation newPlusMarker() // TODO: to avoid warning + // if (!hasPlusMarker(body.tpe)) body modifyType (_ withAnnotation newPlusMarker()) // TODO: to avoid warning val bodyVal = transExpr(body, None, ext) // ??? triggers "cps-transformed unexpectedly" warning in transTailValue treeCopy.CaseDef(cd, transform(pat), transform(guard), bodyVal) } diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala index 801c328177..2a6c1e1967 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala @@ -85,7 +85,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with //gen.mkAttributedSelect(gen.mkAttributedSelect(gen.mkAttributedSelect(gen.mkAttributedIdent(ScalaPackage), //ScalaPackage.tpe.member("util")), ScalaPackage.tpe.member("util").tpe.member("continuations")), MethShiftR) //gen.mkAttributedRef(ModCPS.tpe, MethShiftR) // TODO: correct? - debuglog("funR.tpe = " + funR.tpe) + debuglog("funR.tpe: " + funR.tpe) Apply( TypeApply(funR, targs).setType(appliedType(funR.tpe, targs.map((t:Tree) => t.tpe))), args.map(transform(_)) @@ -97,7 +97,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with debuglog("found shiftUnit: " + tree) atPos(tree.pos) { val funR = gen.mkAttributedRef(MethShiftUnitR) // TODO: correct? - debuglog("funR.tpe = " + funR.tpe) + debuglog("funR.tpe: " + funR.tpe) Apply( TypeApply(funR, List(targs(0), targs(1))).setType(appliedType(funR.tpe, List(targs(0).tpe, targs(1).tpe))), @@ -110,7 +110,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with log("found reify: " + tree) atPos(tree.pos) { val funR = gen.mkAttributedRef(MethReifyR) // TODO: correct? - debuglog("funR.tpe = " + funR.tpe) + debuglog("funR.tpe: " + funR.tpe) Apply( TypeApply(funR, targs).setType(appliedType(funR.tpe, targs.map((t:Tree) => t.tpe))), args.map(transform(_)) diff --git a/src/reflect/scala/reflect/internal/Importers.scala b/src/reflect/scala/reflect/internal/Importers.scala index 29f1c7e1ca..53410b29c5 100644 --- a/src/reflect/scala/reflect/internal/Importers.scala +++ b/src/reflect/scala/reflect/internal/Importers.scala @@ -439,7 +439,7 @@ trait Importers extends api.Importers { self: SymbolTable => if (tt.original != null) mytt.setOriginal(importTree(tt.original)) case _ => if (mytree.hasSymbolField) mytree.symbol = importSymbol(tree.symbol) - mytree.tpe = importType(tree.tpe) + mytree setType importType(tree.tpe) } } }) diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 8e776b8590..fd5c3909b8 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -2632,8 +2632,8 @@ trait Symbols extends api.Symbols { self: SymbolTable => * * {{{ * tsym is an instance of AbstractTypeSymbol - * tsym.info = TypeBounds(Nothing, Number) - * tsym.tpe = TypeRef(NoPrefix, T, List()) + * tsym.info == TypeBounds(Nothing, Number) + * tsym.tpe == TypeRef(NoPrefix, T, List()) * }}} */ class AbstractTypeSymbol protected[Symbols] (initOwner: Symbol, initPos: Position, initName: TypeName) diff --git a/src/reflect/scala/reflect/internal/TreeGen.scala b/src/reflect/scala/reflect/internal/TreeGen.scala index f3aa37bd15..0954432c77 100644 --- a/src/reflect/scala/reflect/internal/TreeGen.scala +++ b/src/reflect/scala/reflect/internal/TreeGen.scala @@ -128,9 +128,9 @@ abstract class TreeGen extends macros.TreeBuilder { else mkAttributedIdent(sym) /** Replaces tree type with a stable type if possible */ - def stabilize(tree: Tree): Tree = { - for(tp <- stableTypeFor(tree)) tree.tpe = tp - tree + def stabilize(tree: Tree): Tree = stableTypeFor(tree) match { + case Some(tp) => tree setType tp + case _ => tree } /** Computes stable type for a tree if possible */ diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 6dc1ff157c..024e1b30bf 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -24,7 +24,9 @@ trait Trees extends api.Trees { self: SymbolTable => private[this] var rawtpe: Type = _ final def tpe = rawtpe - def tpe_=(t: Type) = rawtpe = t + @deprecated("Use setType", "2.11.0") def tpe_=(t: Type): Unit = setType(t) + + def clearType(): this.type = this setType null def setType(tp: Type): this.type = { rawtpe = tp; this } def defineType(tp: Type): this.type = setType(tp) @@ -1402,7 +1404,7 @@ trait Trees extends api.Trees { self: SymbolTable => class ThisSubstituter(clazz: Symbol, to: => Tree) extends Transformer { val newtpe = to.tpe override def transform(tree: Tree) = { - if (tree.tpe ne null) tree.tpe = tree.tpe.substThis(clazz, newtpe) + tree modifyType (_.substThis(clazz, newtpe)) tree match { case This(_) if tree.symbol == clazz => to case _ => super.transform(tree) @@ -1412,8 +1414,7 @@ trait Trees extends api.Trees { self: SymbolTable => class TypeMapTreeSubstituter(val typeMap: TypeMap) extends Traverser { override def traverse(tree: Tree) { - if (tree.tpe ne null) - tree.tpe = typeMap(tree.tpe) + tree modifyType typeMap if (tree.isDef) tree.symbol modifyInfo typeMap @@ -1445,8 +1446,8 @@ trait Trees extends api.Trees { self: SymbolTable => if (tree.symbol == from.head) tree setSymbol to.head else subst(from.tail, to.tail) } + tree modifyType symSubst - if (tree.tpe ne null) tree.tpe = symSubst(tree.tpe) if (tree.hasSymbolField) { subst(from, to) tree match { diff --git a/src/reflect/scala/reflect/macros/Universe.scala b/src/reflect/scala/reflect/macros/Universe.scala index 4e76f7c408..31f3192a85 100644 --- a/src/reflect/scala/reflect/macros/Universe.scala +++ b/src/reflect/scala/reflect/macros/Universe.scala @@ -114,7 +114,7 @@ abstract class Universe extends scala.reflect.api.Universe { def setPos(newpos: Position): Tree /** Sets the `tpe` of the tree. Returns `Unit`. */ - def tpe_=(t: Type): Unit + @deprecated("Use setType", "2.11.0") def tpe_=(t: Type): Unit /** Sets the `tpe` of the tree. Returns the tree itself. */ def setType(tp: Type): Tree @@ -238,4 +238,4 @@ abstract class Universe extends scala.reflect.api.Universe { /** The AST that corresponds to this compilation unit. */ def body: Tree } -} \ No newline at end of file +} -- cgit v1.2.3