Skip to content

Commit

Permalink
Avoid CCE when scalac internally uses compileLate. Fixes #2452
Browse files Browse the repository at this point in the history
For example, when the `--sourcepath` option is provided
and the refchecks phase compiles an annotation found
on a referenced symbol from the sourcepath.

`compileLate` assumes that all non-sentinel compiler
phases can be down cast to `GlobalPhase`.

This commit changes the two phases in SBT to extend
this instead of `Phase`. This has the knock on benefit
of simplifying the phases by letting the `GlobalPhase.run`
iterator over the list of compilation units and feed them
to us one by one.

I checked that the test case failed before making each
change.
  • Loading branch information
retronym authored and eed3si9n committed May 2, 2016
1 parent f3a4608 commit a27be44
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class API(val global: CallbackGlobal) extends Compat {
}

private abstract class TopLevelTraverser extends Traverser {
def `class`(s: Symbol)
def `class`(s: Symbol): Unit
override def traverse(tree: Tree): Unit = {
tree match {
case (_: ClassDef | _: ModuleDef) if isTopLevel(tree.symbol) => `class`(tree.symbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
import global._

def newPhase(prev: Phase): Phase = new DependencyPhase(prev)
private class DependencyPhase(prev: Phase) extends Phase(prev) {
private class DependencyPhase(prev: Phase) extends GlobalPhase(prev) {
override def description = "Extracts dependency information"
def name = Dependency.name
def run: Unit = {
for (unit <- currentRun.units if !unit.isJava) {
def apply(unit: CompilationUnit): Unit = {
if (!unit.isJava) {
// build dependencies structure
val sourceFile = unit.source.file.file
if (global.callback.nameHashing) {
Expand Down
6 changes: 3 additions & 3 deletions internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
import global._

def newPhase(prev: Phase): Phase = new DependencyPhase(prev)
private class DependencyPhase(prev: Phase) extends Phase(prev) {
private class DependencyPhase(prev: Phase) extends GlobalPhase(prev) {
override def description = "Extracts dependency information"
def name = Dependency.name
def run: Unit = {
for (unit <- currentRun.units if !unit.isJava) {
def apply(unit: CompilationUnit): Unit = {
if (!unit.isJava) {
// build dependencies structure
val sourceFile = unit.source.file.file
if (global.callback.nameHashing) {
Expand Down

0 comments on commit a27be44

Please sign in to comment.