softwaremill / scala-clippy

Good advice for Scala compiler errors
Apache License 2.0
312 stars 20 forks source link

Load custom reporter in a plugin component #31

Closed kciesielski closed 7 years ago

kciesielski commented 7 years ago

Direct assignment of our reporter into the global reporter field results in occasional sbt exceptions like:

java.lang.ClassCastException: com.softwaremill.clippy.DelegatingReporter cannot be cast to xsbt.DelegatingReporter
       at xsbt.CachedCompiler0$Compiler.logUnreportedWarnings(CompilerInterface.scala:224)                          
        at xsbt.CachedCompiler0.processUnreportedWarnings(CompilerInterface.scala:145)                               
        at xsbt.CachedCompiler0.run(CompilerInterface.scala:117)                                                     
        at xsbt.CachedCompiler0.run(CompilerInterface.scala:95)                                                      
        at xsbt.CompilerInterface.run(CompilerInterface.scala:26)           

It's caused by sbt delegating reporter doing a direct cast of global reporter in the CachedCompiler.logUnreportedWarnings functions. This PR introduces a custom compilation phase injected between parser and namer. This phase will replace global repoter with Clippy's one and looks like SBT won't do the casting afterwards.

However, our custom phase won't get injected when compilation is started from tests, so I added another "undocumented" plugin option testmode. When true, the reporter assignment will happen as previously.

adamw commented 7 years ago

0.3.6 released