From fdca21eb130a782580cf13df0eb74eb4bceb2370 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 13 Jun 2012 19:20:35 +0200 Subject: Don't use the BrowsingLoader for Java sources. When the presentation compiler needs a SourceLoader, instead of immediately adding the file to the compilation round it uses a fast parser to create symbols for all top-level class definitions. The fast parser assumes Scala sources, which is not always the case. --- src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala b/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala index 25d835790e..52e971f1e7 100644 --- a/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala +++ b/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala @@ -105,7 +105,7 @@ abstract class BrowsingLoaders extends SymbolLoaders { */ override def enterToplevelsFromSource(root: Symbol, name: String, src: AbstractFile) { try { - if (root.isEffectiveRoot) // RootClass or EmptyPackageClass + if (root.isEffectiveRoot || !src.name.endsWith(".scala")) // RootClass or EmptyPackageClass super.enterToplevelsFromSource(root, name, src) else browseTopLevel(root, src) -- cgit v1.2.3 From f4d2678c42a82a2716eac8bc50e39a1d96fb67c0 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 13 Jun 2012 19:22:52 +0200 Subject: Don't require symbols to be loaded in the parser. The parser special-cases primitive types. For comparing the name, it relied on having the symbols for primitive types already loaded, which is not always the case. The presentation compiler may parse sources for, say, scala.Int, and therefore the symbol for Int may not be yet available. --- src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index fd154fe796..bce9f28847 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -253,7 +253,16 @@ self => final val InBlock = 1 final val InTemplate = 2 - lazy val ScalaValueClassNames = tpnme.AnyVal :: definitions.ScalaValueClasses.map(_.name) + lazy val ScalaValueClassNames = Seq(tpnme.AnyVal, + tpnme.Unit, + tpnme.Boolean, + tpnme.Byte, + tpnme.Short, + tpnme.Char, + tpnme.Int, + tpnme.Long, + tpnme.Float, + tpnme.Double) import nme.raw -- cgit v1.2.3 From eaa3dd57f1a56151d0d6abe82f196e92aadaa843 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 13 Jun 2012 19:24:37 +0200 Subject: Remove NPE when `compileLate` sees sources during initialization. When a symbol needed in Definitions is loaded, it may be that the corresponding source is newer than the classfile. That will send it to `compileLate`, but no phase is yet set. We simply add it to the compilation pipeline and continue gracefully. --- src/compiler/scala/tools/nsc/Global.scala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 787c9c7f57..a701e41153 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -1667,13 +1667,14 @@ class Global(var currentSettings: Settings, var reporter: Reporter) /** Compile abstract file until `globalPhase`, but at least to phase "namer". */ def compileLate(unit: CompilationUnit) { - val maxId = math.max(globalPhase.id, typerPhase.id) addUnit(unit) - firstPhase.iterator takeWhile (_.id < maxId) foreach (ph => - atPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit) - ) - refreshProgress + if (firstPhase ne null) { // we might get here during initialization, is a source is newer than the binary + val maxId = math.max(globalPhase.id, typerPhase.id) + firstPhase.iterator takeWhile (_.id < maxId) foreach (ph => + atPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit)) + refreshProgress + } } /** Reset package class to state at typer (not sure what this -- cgit v1.2.3