Skip to content

Commit

Permalink
Merge pull request scala#3502 from retronym/ticket/8258
Browse files Browse the repository at this point in the history
Fix regression for using Scala IDE on scala-library
  • Loading branch information
gkossakowski committed Feb 10, 2014
2 parents 90aa12e + 894aee1 commit c611f7b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/compiler/scala/tools/nsc/typechecker/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ trait Contexts { self: Analyzer =>
if (settings.noimports) Nil
else if (unit.isJava) RootImports.javaList
else if (settings.nopredef || treeInfo.noPredefImportForUnit(unit.body)) {
// SI-8258 Needed for the presentation compiler using -sourcepath, otherwise cycles can occur. See the commit
// message for this ticket for an example.
debuglog("Omitted import of Predef._ for " + unit)
RootImports.javaAndScalaList
}
Expand Down
15 changes: 12 additions & 3 deletions src/interactive/scala/tools/nsc/interactive/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
threadId += 1
compileRunner = new PresentationCompilerThread(this, projectName)
compileRunner.setDaemon(true)
compileRunner.start()
compileRunner
}

Expand Down Expand Up @@ -1253,11 +1252,21 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")

forceSymbolsUsedByParser()

/** Start the compiler background thread and turn on thread confinement checks */
private def finishInitialization(): Unit = {
// this flag turns on `assertCorrectThread checks`
initializing = false

// Only start the thread if initialization was successful. A crash while forcing symbols (for example
// if the Scala library is not on the classpath) can leave running threads behind. See Scala IDE #1002016
compileRunner.start()
}

/** The compiler has been initialized. Constructors are evaluated in textual order,
* so this is set to true only after all super constructors and the primary constructor
* if we reached here, all super constructors and the primary constructor
* have been executed.
*/
initializing = false
finishInitialization()
}

object CancelException extends Exception
22 changes: 19 additions & 3 deletions src/reflect/scala/reflect/internal/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,17 @@ abstract class TreeInfo {
unapply(dissectApplied(tree))
}

/** Does list of trees start with a definition of
* a class of module with given name (ignoring imports)
*/
def firstDefinesClassOrObject(trees: List[Tree], name: Name): Boolean = trees match {
case Import(_, _) :: xs => firstDefinesClassOrObject(xs, name)
case Annotated(_, tree1) :: _ => firstDefinesClassOrObject(List(tree1), name)
case ModuleDef(_, `name`, _) :: _ => true
case ClassDef(_, `name`, _, _) :: _ => true
case _ => false
}

/** Locates the synthetic Apply node corresponding to an extractor's call to
* unapply (unwrapping nested Applies) and returns the fun part of that Apply.
*/
Expand All @@ -750,8 +761,7 @@ abstract class TreeInfo {
}

/** Is this file the body of a compilation unit which should not
* have Predef imported? This is the case iff the first import in the
* unit explicitly refers to Predef.
* have Predef imported?
*/
def noPredefImportForUnit(body: Tree) = {
// Top-level definition whose leading imports include Predef.
Expand All @@ -760,7 +770,13 @@ abstract class TreeInfo {
case Import(expr, _) => isReferenceToPredef(expr)
case _ => false
}
isLeadingPredefImport(body)
// Compilation unit is class or object 'name' in package 'scala'
def isUnitInScala(tree: Tree, name: Name) = tree match {
case PackageDef(Ident(nme.scala_), defs) => firstDefinesClassOrObject(defs, name)
case _ => false
}

isUnitInScala(body, nme.Predef) || isLeadingPredefImport(body)
}

def isAbsTypeDef(tree: Tree) = tree match {
Expand Down

0 comments on commit c611f7b

Please sign in to comment.