Skip to content

Commit

Permalink
Avoids loading scala.package and scala.reflect.package from source if…
Browse files Browse the repository at this point in the history
… a classfile exists.

We know that loading these packages from source leads to compilation errors. To reproduce: Update scala.reflect.package, make sure it is on the source path and recompile anything using it. You will get a number of errors having to do with ClassTags and macro expansions. With the patch, these errors go away because the package is not loaded as long as a classfile exists.
  • Loading branch information
odersky committed Jul 26, 2012
1 parent ad08f24 commit 54bab79
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,23 @@ abstract class SymbolLoaders {
enterClassAndModule(root, name, new SourcefileLoader(src))
}

/** The package objects of scala and scala.reflect should always
* be loaded in binary if classfiles are available, even if sourcefiles
* are newer. Late-compiling these objects from source leads to compilation
* order issues.
* Note: We do a name-base comparison here because the method is called before we even
* have ReflectPackage defined.
*/
def binaryOnly(owner: Symbol, name: String): Boolean =
name == "package" &&
(owner.fullName == "scala" || owner.fullName == "scala.reflect")

/** Initialize toplevel class and module symbols in `owner` from class path representation `classRep`
*/
def initializeFromClassPath(owner: Symbol, classRep: ClassPath[platform.BinaryRepr]#ClassRep) {
((classRep.binary, classRep.source) : @unchecked) match {
case (Some(bin), Some(src)) if platform.needCompile(bin, src) =>
case (Some(bin), Some(src))
if platform.needCompile(bin, src) && !binaryOnly(owner, classRep.name) =>
if (settings.verbose.value) inform("[symloader] picked up newer source file for " + src.path)
global.loaders.enterToplevelsFromSource(owner, classRep.name, src)
case (None, Some(src)) =>
Expand Down

0 comments on commit 54bab79

Please sign in to comment.