diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker')
8 files changed, 66 insertions, 64 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 974c0842d3..98ee4ad94d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -516,7 +516,7 @@ trait Contexts { self: Analyzer => argContext.scope enter e.sym } } - if (c.isLocal && !c.owner.isLocalDummy) { + if (c.owner.isTerm && !c.owner.isLocalDummy) { enterElems(c.outer) enterLocalElems(c.scope.elems) } @@ -589,9 +589,6 @@ trait Contexts { self: Analyzer => else if (bufferErrors) reportBuffer += (pos -> msg) } - /** Is the owning symbol of this context a term? */ - final def isLocal: Boolean = owner.isTerm - // nextOuter determines which context is searched next for implicits // (after `this`, which contributes `newImplicits` below.) In // most cases, it is simply the outer context: if we're owned by @@ -714,7 +711,7 @@ trait Contexts { self: Analyzer => ( (ab.isTerm || ab == rootMirror.RootClass) || (accessWithin(ab) || accessWithinLinked(ab)) && - ( !sym.hasLocalFlag + ( !sym.isLocalToThis || sym.owner.isImplClass // allow private local accesses to impl classes || sym.isProtected && isSubThisType(pre, sym.owner) || pre =:= sym.owner.thisType @@ -980,7 +977,7 @@ trait Contexts { self: Analyzer => // 2) sym.owner is inherited by the correct package object class // We try to establish 1) by inspecting the owners directly, and then we try // to rule out 2), and only if both those fail do we resort to looking in the info. - !sym.isPackage && sym.owner.exists && ( + !sym.hasPackageFlag && sym.owner.exists && ( if (sym.owner.isPackageObjectClass) sym.owner.owner == pkgClass else diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 8f5778862d..2bb874a8aa 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -402,8 +402,8 @@ trait Implicits { } def complexity(tp: Type): Int = tp.dealias match { case NoPrefix => 0 - case SingleType(pre, sym) => if (sym.isPackage) 0 else complexity(tp.dealiasWiden) - case ThisType(sym) => if (sym.isPackage) 0 else 1 + case SingleType(pre, sym) => if (sym.hasPackageFlag) 0 else complexity(tp.dealiasWiden) + case ThisType(sym) => if (sym.hasPackageFlag) 0 else 1 case TypeRef(pre, sym, args) => complexity(pre) + (args map complexity).sum + 1 case RefinedType(parents, _) => (parents map complexity).sum + 1 case _ => 1 @@ -425,11 +425,11 @@ trait Implicits { * expected type. * Detect infinite search trees for implicits. * - * @param info The given implicit info describing the implicit definition - * @param isLocal Is the implicit in the local scope of the call site? - * @pre `info.tpe` does not contain an error + * @param info The given implicit info describing the implicit definition + * @param isLocalToCallsite Is the implicit in the local scope of the call site? + * @pre `info.tpe` does not contain an error */ - private def typedImplicit(info: ImplicitInfo, ptChecked: Boolean, isLocal: Boolean): SearchResult = { + private def typedImplicit(info: ImplicitInfo, ptChecked: Boolean, isLocalToCallsite: Boolean): SearchResult = { // SI-7167 let implicit macros decide what amounts for a divergent implicit search // imagine a macro writer which wants to synthesize a complex implicit Complex[T] by making recursive calls to Complex[U] for its parts // e.g. we have `class Foo(val bar: Bar)` and `class Bar(val x: Int)` @@ -450,7 +450,7 @@ trait Implicits { try { context.openImplicits = OpenImplicit(info, pt, tree) :: context.openImplicits // println(" "*context.openImplicits.length+"typed implicit "+info+" for "+pt) //@MDEBUG - val result = typedImplicit0(info, ptChecked, isLocal) + val result = typedImplicit0(info, ptChecked, isLocalToCallsite) if (result.isDivergent) { //println("DivergentImplicit for pt:"+ pt +", open implicits:"+context.openImplicits) //@MDEBUG if (context.openImplicits.tail.isEmpty && !pt.isErroneous) @@ -574,24 +574,24 @@ trait Implicits { case _ => false } - private def typedImplicit0(info: ImplicitInfo, ptChecked: Boolean, isLocal: Boolean): SearchResult = { + private def typedImplicit0(info: ImplicitInfo, ptChecked: Boolean, isLocalToCallsite: Boolean): SearchResult = { if (Statistics.canEnable) Statistics.incCounter(plausiblyCompatibleImplicits) val ok = ptChecked || matchesPt(info) && { - def word = if (isLocal) "local " else "" + def word = if (isLocalToCallsite) "local " else "" typingLog("match", s"$word$info") true } - if (ok) typedImplicit1(info, isLocal) else SearchFailure + if (ok) typedImplicit1(info, isLocalToCallsite) else SearchFailure } - private def typedImplicit1(info: ImplicitInfo, isLocal: Boolean): SearchResult = { + private def typedImplicit1(info: ImplicitInfo, isLocalToCallsite: Boolean): SearchResult = { if (Statistics.canEnable) Statistics.incCounter(matchingImplicits) // workaround for deficient context provided by ModelFactoryImplicitSupport#makeImplicitConstraints val isScalaDoc = context.tree == EmptyTree val itree0 = atPos(pos.focus) { - if (isLocal && !isScalaDoc) { + if (isLocalToCallsite && !isScalaDoc) { // SI-4270 SI-5376 Always use an unattributed Ident for implicits in the local scope, // rather than an attributed Select, to detect shadowing. Ident(info.name) @@ -661,7 +661,7 @@ trait Implicits { fail("hasMatchingSymbol reported error: " + context.firstError.get.errMsg) else if (itree3.isErroneous) fail("error typechecking implicit candidate") - else if (isLocal && !hasMatchingSymbol(itree2)) + else if (isLocalToCallsite && !hasMatchingSymbol(itree2)) fail("candidate implicit %s is shadowed by %s".format( info.sym.fullLocationString, itree2.symbol.fullLocationString)) else { @@ -776,12 +776,12 @@ trait Implicits { /** Prune ImplicitInfos down to either all the eligible ones or the best one. * - * @param iss list of list of infos - * @param isLocal if true, `iss` represents in-scope implicits, which must respect the normal rules of - * shadowing. The head of the list `iss` must represent implicits from the closest - * enclosing scope, and so on. + * @param iss list of list of infos + * @param isLocalToCallsite if true, `iss` represents in-scope implicits, which must respect the normal rules of + * shadowing. The head of the list `iss` must represent implicits from the closest + * enclosing scope, and so on. */ - class ImplicitComputation(iss: Infoss, isLocal: Boolean) { + class ImplicitComputation(iss: Infoss, isLocalToCallsite: Boolean) { abstract class Shadower { def addInfos(infos: Infos) def isShadowed(name: Name): Boolean @@ -800,7 +800,7 @@ trait Implicits { def addInfos(infos: Infos) {} def isShadowed(name: Name) = false } - if (isLocal) new LocalShadower else NoShadower + if (isLocalToCallsite) new LocalShadower else NoShadower } private var best: SearchResult = SearchFailure @@ -870,7 +870,7 @@ trait Implicits { @tailrec private def rankImplicits(pending: Infos, acc: Infos): Infos = pending match { case Nil => acc case i :: is => - DivergentImplicitRecovery(typedImplicit(i, ptChecked = true, isLocal), i) match { + DivergentImplicitRecovery(typedImplicit(i, ptChecked = true, isLocalToCallsite), i) match { case sr if sr.isDivergent => Nil case sr if sr.isFailure => @@ -898,7 +898,7 @@ trait Implicits { /** Returns all eligible ImplicitInfos and their SearchResults in a map. */ - def findAll() = mapFrom(eligible)(typedImplicit(_, ptChecked = false, isLocal)) + def findAll() = mapFrom(eligible)(typedImplicit(_, ptChecked = false, isLocalToCallsite)) /** Returns the SearchResult of the best match. */ @@ -940,15 +940,15 @@ trait Implicits { /** Computes from a list of lists of implicit infos a map which takes * infos which are applicable for given expected type `pt` to their attributed trees. * - * @param iss The given list of lists of implicit infos - * @param isLocal Is implicit definition visible without prefix? - * If this is the case then symbols in preceding lists shadow - * symbols of the same name in succeeding lists. - * @return map from infos to search results + * @param iss The given list of lists of implicit infos + * @param isLocalToCallsite Is implicit definition visible without prefix? + * If this is the case then symbols in preceding lists shadow + * symbols of the same name in succeeding lists. + * @return map from infos to search results */ - def applicableInfos(iss: Infoss, isLocal: Boolean): Map[ImplicitInfo, SearchResult] = { + def applicableInfos(iss: Infoss, isLocalToCallsite: Boolean): Map[ImplicitInfo, SearchResult] = { val start = if (Statistics.canEnable) Statistics.startCounter(subtypeAppInfos) else null - val computation = new ImplicitComputation(iss, isLocal) { } + val computation = new ImplicitComputation(iss, isLocalToCallsite) { } val applicable = computation.findAll() if (Statistics.canEnable) Statistics.stopCounter(subtypeAppInfos, start) @@ -959,14 +959,14 @@ trait Implicits { * If found return a search result with a tree from found implicit info * which is typed with expected type `pt`. Otherwise return SearchFailure. * - * @param implicitInfoss The given list of lists of implicit infos - * @param isLocal Is implicit definition visible without prefix? - * If this is the case then symbols in preceding lists shadow - * symbols of the same name in succeeding lists. + * @param implicitInfoss The given list of lists of implicit infos + * @param isLocalToCallsite Is implicit definition visible without prefix? + * If this is the case then symbols in preceding lists shadow + * symbols of the same name in succeeding lists. */ - def searchImplicit(implicitInfoss: Infoss, isLocal: Boolean): SearchResult = + def searchImplicit(implicitInfoss: Infoss, isLocalToCallsite: Boolean): SearchResult = if (implicitInfoss.forall(_.isEmpty)) SearchFailure - else new ImplicitComputation(implicitInfoss, isLocal) findBest() + else new ImplicitComputation(implicitInfoss, isLocalToCallsite) findBest() /** Produce an implicict info map, i.e. a map from the class symbols C of all parts of this type to * the implicit infos in the companion objects of these class symbols C. @@ -1271,7 +1271,8 @@ trait Implicits { return SearchFailure } val cm = typed(Ident(ReflectRuntimeCurrentMirror)) - val interop = gen.mkMethodCall(ReflectRuntimeUniverse, nme.typeTagToManifest, List(tp), List(cm, tagInScope)) + val internal = gen.mkAttributedSelect(gen.mkAttributedRef(ReflectRuntimeUniverse), UniverseInternal) + val interop = gen.mkMethodCall(Select(internal, nme.typeTagToManifest), List(tp), List(cm, tagInScope)) wrapResult(interop) } } else { @@ -1326,7 +1327,7 @@ trait Implicits { val failstart = if (Statistics.canEnable) Statistics.startTimer(inscopeFailNanos) else null val succstart = if (Statistics.canEnable) Statistics.startTimer(inscopeSucceedNanos) else null - var result = searchImplicit(context.implicitss, isLocal = true) + var result = searchImplicit(context.implicitss, isLocalToCallsite = true) if (result.isFailure) { if (Statistics.canEnable) Statistics.stopTimer(inscopeFailNanos, failstart) @@ -1344,7 +1345,7 @@ trait Implicits { // `materializeImplicit` does some preprocessing for `pt` // is it only meant for manifests/tags or we need to do the same for `implicitsOfExpectedType`? if (result.isFailure && !wasAmbigious) - result = searchImplicit(implicitsOfExpectedType, isLocal = false) + result = searchImplicit(implicitsOfExpectedType, isLocalToCallsite = false) if (result.isFailure) { context.updateBuffer(previousErrs) @@ -1383,8 +1384,11 @@ trait Implicits { } def allImplicits: List[SearchResult] = { - def search(iss: Infoss, isLocal: Boolean) = applicableInfos(iss, isLocal).values - (search(context.implicitss, isLocal = true) ++ search(implicitsOfExpectedType, isLocal = false)).toList.filter(_.tree ne EmptyTree) + def search(iss: Infoss, isLocalToCallsite: Boolean) = applicableInfos(iss, isLocalToCallsite).values + ( + search(context.implicitss, isLocalToCallsite = true) ++ + search(implicitsOfExpectedType, isLocalToCallsite = false) + ).toList.filter(_.tree ne EmptyTree) } // find all implicits for some type that contains type variables @@ -1392,8 +1396,8 @@ trait Implicits { def allImplicitsPoly(tvars: List[TypeVar]): List[(SearchResult, List[TypeConstraint])] = { def resetTVars() = tvars foreach { _.constr = new TypeConstraint } - def eligibleInfos(iss: Infoss, isLocal: Boolean) = { - val eligible = new ImplicitComputation(iss, isLocal).eligible + def eligibleInfos(iss: Infoss, isLocalToCallsite: Boolean) = { + val eligible = new ImplicitComputation(iss, isLocalToCallsite).eligible eligible.toList.flatMap { (ii: ImplicitInfo) => // each ImplicitInfo contributes a distinct set of constraints (generated indirectly by typedImplicit) @@ -1402,12 +1406,13 @@ trait Implicits { // any previous errors should not affect us now context.flushBuffer() - val res = typedImplicit(ii, ptChecked = false, isLocal) + val res = typedImplicit(ii, ptChecked = false, isLocalToCallsite) if (res.tree ne EmptyTree) List((res, tvars map (_.constr))) else Nil } } - eligibleInfos(context.implicitss, isLocal = true) ++ eligibleInfos(implicitsOfExpectedType, isLocal = false) + eligibleInfos(context.implicitss, isLocalToCallsite = true) ++ + eligibleInfos(implicitsOfExpectedType, isLocalToCallsite = false) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 9b5b0e1f37..23dc57d5b9 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -374,7 +374,7 @@ trait Namers extends MethodSynthesis { } val existing = pkgOwner.info.decls.lookup(pid.name) - if (existing.isPackage && pkgOwner == existing.owner) + if (existing.hasPackageFlag && pkgOwner == existing.owner) existing else { val pkg = pkgOwner.newPackage(pid.name.toTermName, pos) diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 916b8a3e0c..b166bf988d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -908,7 +908,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans var index = -1 for (stat <- stats) { index = index + 1 - def enterSym(sym: Symbol) = if (sym.isLocal) { + def enterSym(sym: Symbol) = if (sym.isLocalToBlock) { currentLevel.scope.enter(sym) symIndex(sym) = index } @@ -925,7 +925,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans } private def enterReference(pos: Position, sym: Symbol) { - if (sym.isLocal) { + if (sym.isLocalToBlock) { val e = currentLevel.scope.lookupEntry(sym.name) if ((e ne null) && sym == e.sym) { var l = currentLevel @@ -1230,7 +1230,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans if (tree1.symbol.isLazy) tree1 :: Nil else { val lazySym = tree.symbol.lazyAccessorOrSelf - if (lazySym.isLocal && index <= currentLevel.maxindex) { + if (lazySym.isLocalToBlock && index <= currentLevel.maxindex) { debuglog("refsym = " + currentLevel.refsym) unit.error(currentLevel.refpos, "forward reference extends over definition of " + lazySym) } @@ -1549,7 +1549,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans if (!sym.exists) devWarning("Select node has NoSymbol! " + tree + " / " + tree.tpe) - else if (sym.hasLocalFlag) + else if (sym.isLocalToThis) varianceValidator.checkForEscape(sym, currentClass) def checkSuper(mix: Name) = @@ -1758,7 +1758,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans result match { case ClassDef(_, _, _, _) | TypeDef(_, _, _, _) => - if (result.symbol.isLocal || result.symbol.isTopLevel) + if (result.symbol.isLocalToBlock || result.symbol.isTopLevel) varianceValidator.traverse(result) case tt @ TypeTree() if tt.original != null => varianceValidator.traverse(tt.original) // See SI-7872 diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 06796eca8e..87da565142 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -71,7 +71,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT acc setInfoAndEnter (tpe cloneInfo acc) // Diagnostic for SI-7091 if (!accDefs.contains(clazz)) - reporter.error(sel.pos, s"Internal error: unable to store accessor definition in ${clazz}. clazz.isPackage=${clazz.isPackage}. Accessor required for ${sel} (${showRaw(sel)})") + reporter.error(sel.pos, s"Internal error: unable to store accessor definition in ${clazz}. clazz.hasPackageFlag=${clazz.hasPackageFlag}. Accessor required for ${sel} (${showRaw(sel)})") else storeAccessorDefinition(clazz, DefDef(acc, EmptyTree)) acc } @@ -224,7 +224,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT if (settings.lint) { if (sym.isPrivateLocal && sym.paramss.isEmpty) { qual.symbol.ancestors foreach { parent => - parent.info.decls filterNot (x => x.isPrivate || x.hasLocalFlag) foreach { m2 => + parent.info.decls filterNot (x => x.isPrivate || x.isLocalToThis) foreach { m2 => if (sym.name == m2.name && m2.isGetter && m2.accessed.isMutable) { unit.warning(sel.pos, sym.accessString + " " + sym.fullLocationString + " shadows mutable " + m2.name diff --git a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala index fd8f9bebba..a2f52e1905 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala @@ -376,7 +376,7 @@ abstract class TreeCheckers extends Analyzer { def isOk(sym: Symbol) = treeSym hasTransOwner sym.enclosingSuchThat(x => !x.isTypeParameterOrSkolem) // account for higher order type params def isEligible(sym: Symbol) = (sym ne NoSymbol) && ( sym.isTypeParameter - || sym.isLocal + || sym.isLocalToBlock ) val referencedSymbols = (treeSym :: referencesInType(treeInfo)).distinct filter (sym => isEligible(sym) && !isOk(sym)) def mk[T](what: String, x: T, str: T => String = (x: T) => "" + x): ((Any, String)) = diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index dfa1b6db0f..60346e7be1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -452,10 +452,10 @@ trait TypeDiagnostics { val treeTypes = mutable.Set[Type]() def defnSymbols = defnTrees.toList map (_.symbol) - def localVars = defnSymbols filter (t => t.isLocal && t.isVar) + def localVars = defnSymbols filter (t => t.isLocalToBlock && t.isVar) def qualifiesTerm(sym: Symbol) = ( - (sym.isModule || sym.isMethod || sym.isPrivateLocal || sym.isLocal) + (sym.isModule || sym.isMethod || sym.isPrivateLocal || sym.isLocalToBlock) && !nme.isLocalName(sym.name) && !sym.isParameter && !sym.isParamAccessor // could improve this, but it's a pain @@ -499,12 +499,12 @@ trait TypeDiagnostics { def isUnusedType(m: Symbol): Boolean = ( m.isType && !m.isTypeParameterOrSkolem // would be nice to improve this - && (m.isPrivate || m.isLocal) + && (m.isPrivate || m.isLocalToBlock) && !(treeTypes.exists(tp => tp exists (t => t.typeSymbolDirect == m))) ) def isUnusedTerm(m: Symbol): Boolean = ( (m.isTerm) - && (m.isPrivate || m.isLocal) + && (m.isPrivate || m.isLocalToBlock) && !targets(m) && !(m.name == nme.WILDCARD) // e.g. val _ = foo && !ignoreNames(m.name.toTermName) // serialization methods diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index f4d2a2cea0..8721450dc9 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -393,7 +393,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper if (sym.isPrivate && !sym.hasFlag(SYNTHETIC_PRIVATE)) { var o = owner while (o != NoSymbol && o != sym.owner && o != sym.owner.linkedClassOfClass && - !o.isLocal && !o.isPrivate && + !o.isLocalToBlock && !o.isPrivate && !o.privateWithin.hasTransOwner(sym.owner)) o = o.owner if (o == sym.owner || o == sym.owner.linkedClassOfClass) @@ -3015,7 +3015,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper /* 'accessor' and 'accessed' are so similar it becomes very difficult to * follow the logic, so I renamed one to something distinct. */ - def accesses(looker: Symbol, accessed: Symbol) = accessed.hasLocalFlag && ( + def accesses(looker: Symbol, accessed: Symbol) = accessed.isLocalToThis && ( (accessed.isParamAccessor) || (looker.hasAccessorFlag && !accessed.hasAccessorFlag && accessed.isPrivate) ) |