summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/Global.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/tools/nsc/Global.scala')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 8c8d0be322..191016e133 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -777,7 +777,8 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
/** Compile list of source files */
def compileSources(_sources: List[SourceFile]) {
- val sources = dependencyAnalysis.filter(_sources.removeDuplicates) // bug #1268, scalac confused by duplicated filenames
+ val depSources = dependencyAnalysis.filter(_sources.removeDuplicates) // bug #1268, scalac confused by duplicated filenames
+ val sources = pkgObjectsFirst(depSources)
if (reporter.hasErrors)
return // there is a problem already, e.g. a
// plugin was passed a bad option
@@ -921,6 +922,27 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
}
if (!pclazz.isRoot) resetPackageClass(pclazz.owner)
}
+
+ private def pkgObjectsFirst(files: List[SourceFile]) = {
+ def inScalaFolder(f: SourceFile) =
+ f.file.container.name == "scala"
+ val res = new ListBuffer[SourceFile]
+ var scalaObject: Option[SourceFile] = None
+ var lowPriorityImplicits: Option[SourceFile] = None
+ var predef: Option[SourceFile] = None
+ for (file <- files) file.file.name match {
+ case "ScalaObject.scala" if inScalaFolder(file) => scalaObject = Some(file)
+ case "LowPriorityImplicits.scala" if inScalaFolder(file) => lowPriorityImplicits = Some(file)
+ case "Predef.scala" if inScalaFolder(file) => predef = Some(file)
+ case "package.scala" => file +=: res // prepend package objects
+ case _ => res += file // append all others
+ }
+ val f: SourceFile => Unit = res.+=:(_)
+ predef map f // Predef 3rd
+ lowPriorityImplicits map f // LowPriorityImplicits 2nd
+ scalaObject map f // ScalaObject 1st
+ res.toList // then package objects, then others
+ }
} // class Run
def printAllUnits() {