Skip to content

Commit ea36cad

Browse files
committed
SI-8258 Revert "SI-7335 Remove special case for import of Predef._
This reverts commit 6690455. Conflicts: src/reflect/scala/reflect/internal/TreeInfo.scala As evidenced by the highlights of the stack trace in Scala IDE, my assertion in the 6690455 wasn't universally true. The change was only motivated by removing a special case, not in order to fix some other problem. So the revert is the most straight forward course of action for now. I haven't pinned this down with a test outside of Eclipse, and given the lateness of the hour wrt 2.11.0, I'll have to submit without one. 2013-03-10 08:38:04,690 ERROR [main] - org.scala-ide.sdt.core - org.scala-ide.sdt.core - org.scala-ide.sdt.core - 0 - Error during askOption scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving object Predef ... at scala.reflect.internal.Symbols$Symbol.lock(Symbols.scala:482) at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1216) at scala.reflect.internal.Symbols$Symbol.tpe(Symbols.scala:1200) at scala.reflect.internal.Symbols$Symbol.tpeHK(Symbols.scala:1201) at scala.reflect.internal.Types$Type.computeMemberType(Types.scala:784) at scala.reflect.internal.Types$Type.memberType(Types.scala:781) at scala.reflect.internal.TreeGen.mkAttributedSelect(TreeGen.scala:203) ... at scala.reflect.internal.TreeGen.mkAttributedStableRef(TreeGen.scala:162) at scala.tools.nsc.ast.TreeGen.mkWildcardImport(TreeGen.scala:39) at scala.tools.nsc.typechecker.Contexts$Context.makeNewImport(Contexts.scala:308) at scala.tools.nsc.typechecker.Contexts$class.rootContext(Contexts.scala:69) at scala.tools.nsc.Global$$anon$1.rootContext(Global.scala:492) at scala.tools.nsc.typechecker.Contexts$class.rootContext(Contexts.scala:64) at scala.tools.nsc.Global$$anon$1.rootContext(Global.scala:492) at scala.tools.nsc.typechecker.Analyzer$namerFactory$$anon$1.apply(Analyzer.scala:43) at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:463) ... at scala.tools.nsc.Global$Run.compileLate(Global.scala:1681) at scala.tools.nsc.Global$Run.compileLate(Global.scala:1671) at scala.tools.nsc.symtab.SymbolLoaders$SourcefileLoader.doComplete(SymbolLoaders.scala:284) at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:187) at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1229) at scala.reflect.internal.Symbols$Symbol.tpe(Symbols.scala:1200) at scala.reflect.internal.Symbols$Symbol.tpeHK(Symbols.scala:1201) at scala.reflect.internal.Types$Type.computeMemberType(Types.scala:784) at scala.reflect.internal.Types$Type.memberType(Types.scala:781) at scala.reflect.internal.TreeGen.mkAttributedSelect(TreeGen.scala:203) at scala.reflect.internal.TreeGen.mkAttributedRef(TreeGen.scala:124) at scala.reflect.internal.TreeGen.mkAttributedRef(TreeGen.scala:130) at scala.reflect.internal.TreeGen.mkAttributedStableRef(TreeGen.scala:162) at scala.tools.nsc.ast.TreeGen.mkWildcardImport(TreeGen.scala:39) ... at scala.tools.nsc.Global$$anon$1.rootContext(Global.scala:492) at scala.tools.nsc.typechecker.Analyzer$namerFactory$$anon$1.apply(Analyzer.scala:43) at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:463) ... at scala.tools.nsc.Global$Run.compileLate(Global.scala:1671) at scala.tools.nsc.symtab.SymbolLoaders$SourcefileLoader.doComplete(SymbolLoaders.scala:284) at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:187) at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1229) at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1365) ... at scala.collection.immutable.HashSet$HashSet1.foreach(HashSet.scala:153) at scala.collection.immutable.HashSet$HashTrieSet.foreach(HashSet.scala:306) at scala.tools.eclipse.javaelements.ScalaJavaMapper$class.initializeRequiredSymbols(ScalaJavaMapper.scala:29) ... at scala.tools.nsc.util.InterruptReq.execute(InterruptReq.scala:26) at scala.tools.nsc.interactive.Global.pollForWork(Global.scala:340)
1 parent 0c16bb0 commit ea36cad

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ trait Contexts { self: Analyzer =>
8989
if (settings.noimports) Nil
9090
else if (unit.isJava) RootImports.javaList
9191
else if (settings.nopredef || treeInfo.noPredefImportForUnit(unit.body)) {
92+
// SI-8258 Needed for the presentation compiler using -sourcepath, otherwise cycles can occur. See the commit
93+
// message for this ticket for an example.
9294
debuglog("Omitted import of Predef._ for " + unit)
9395
RootImports.javaAndScalaList
9496
}

src/reflect/scala/reflect/internal/TreeInfo.scala

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,17 @@ abstract class TreeInfo {
735735
unapply(dissectApplied(tree))
736736
}
737737

738+
/** Does list of trees start with a definition of
739+
* a class of module with given name (ignoring imports)
740+
*/
741+
def firstDefinesClassOrObject(trees: List[Tree], name: Name): Boolean = trees match {
742+
case Import(_, _) :: xs => firstDefinesClassOrObject(xs, name)
743+
case Annotated(_, tree1) :: _ => firstDefinesClassOrObject(List(tree1), name)
744+
case ModuleDef(_, `name`, _) :: _ => true
745+
case ClassDef(_, `name`, _, _) :: _ => true
746+
case _ => false
747+
}
748+
738749
/** Locates the synthetic Apply node corresponding to an extractor's call to
739750
* unapply (unwrapping nested Applies) and returns the fun part of that Apply.
740751
*/
@@ -750,8 +761,7 @@ abstract class TreeInfo {
750761
}
751762

752763
/** Is this file the body of a compilation unit which should not
753-
* have Predef imported? This is the case iff the first import in the
754-
* unit explicitly refers to Predef.
764+
* have Predef imported?
755765
*/
756766
def noPredefImportForUnit(body: Tree) = {
757767
// Top-level definition whose leading imports include Predef.
@@ -760,7 +770,13 @@ abstract class TreeInfo {
760770
case Import(expr, _) => isReferenceToPredef(expr)
761771
case _ => false
762772
}
763-
isLeadingPredefImport(body)
773+
// Compilation unit is class or object 'name' in package 'scala'
774+
def isUnitInScala(tree: Tree, name: Name) = tree match {
775+
case PackageDef(Ident(nme.scala_), defs) => firstDefinesClassOrObject(defs, name)
776+
case _ => false
777+
}
778+
779+
isUnitInScala(body, nme.Predef) || isLeadingPredefImport(body)
764780
}
765781

766782
def isAbsTypeDef(tree: Tree) = tree match {

0 commit comments

Comments
 (0)