Skip to content

SBT incompatible with --srcpath: ClassCastException: xsbt.API$ApiPhase cannot be cast to scala.tools.nsc.Global$GlobalPhase #2452

@retronym

Description

@retronym

The --sourcepath setting is needed when compiling the Scala standard library. However, when using this in SBT, and recompiling a subset of files in the library, we can run into a CCE.

Here's a demonstration project.

% sbt clean compile
[info] Loading global plugins from /Users/jason/.sbt/0.13/plugins
[info] Loading project definition from /Users/jason/code/sbt-sourcepath-bug/project
[info] Set current project to sbt-sourcepath-bug (in build file:/Users/jason/code/sbt-sourcepath-bug/)
[success] Total time: 0 s, completed 10/02/2016 10:32:45 PM
[info] Updating {file:/Users/jason/code/sbt-sourcepath-bug/}sbt-sourcepath-bug...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/jason/code/sbt-sourcepath-bug/target/scala-2.11/classes...
java.lang.ClassCastException: xsbt.API$ApiPhase cannot be cast to scala.tools.nsc.Global$GlobalPhase
    at scala.tools.nsc.Global$Run$$anonfun$compileLate$2$$anonfun$apply$1.apply(Global.scala:1609)
    at scala.tools.nsc.Global$Run$$anonfun$compileLate$2$$anonfun$apply$1.apply(Global.scala:1609)
    at scala.reflect.internal.SymbolTable.enteringPhase(SymbolTable.scala:235)
    at scala.tools.nsc.Global$Run$$anonfun$compileLate$2.apply(Global.scala:1609)
    at scala.tools.nsc.Global$Run$$anonfun$compileLate$2.apply(Global.scala:1608)
    at scala.collection.Iterator$class.foreach(Iterator.scala:742)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1194)
    at scala.tools.nsc.Global$Run.compileLate(Global.scala:1608)
    at scala.tools.nsc.Global$Run.compileLate(Global.scala:1598)

/cc @Blaisorblade (who mentioned this before https://groups.google.com/d/msg/scala-internals/-E7Q7DXW-BE/Nw6kRhoTkRgJ) and /cc scoverage/sbt-scoverage#116 (which is the same sort of issue.)

It seems that one should always extends GlobalPhase, rather than Phase (other than the sentinel phases NoPhase and SomePhase!)

I am working on a fix in SBT itself here: https://github.com/sbt/sbt/compare/0.13...retronym:topic/sourcepath?expand=1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions