Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit c88b0b3

Browse files
committed
Merge pull request #16 from adriaanm/scalap-M8-RC1
SI-8345 support both scalap 2.11.0-M8 and 2.11.0-RC1
2 parents dc20dbb + c9acb81 commit c88b0b3

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/main/scala/scala/tools/partest/nest/Runner.scala

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import scala.tools.nsc.{ Settings, CompilerCommand, Global }
2121
import scala.tools.nsc.io.{ AbstractFile }
2222
import scala.tools.nsc.reporters.ConsoleReporter
2323
import scala.tools.nsc.util.{ Exceptional, stackTraceString }
24-
import scala.tools.scalap.Main.decompileScala
25-
import scala.tools.scalap.scalasig.ByteCode
2624
import scala.util.{ Try, Success, Failure }
2725
import ClassPath.{ join, split }
2826
import TestState.{ Pass, Fail, Crash, Uninitialized, Updated }
@@ -683,16 +681,40 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
683681
lastState
684682
}
685683

684+
private def decompileClass(clazz: Class[_], isPackageObject: Boolean): String = {
685+
import scala.tools.scalap
686+
687+
// TODO: remove use of reflection once Scala 2.11.0-RC1 is out
688+
// have to use reflection to work on both 2.11.0-M8 and 2.11.0-RC1.
689+
// Once we require only 2.11.0-RC1, replace the following block by:
690+
// import scalap.scalax.rules.scalasig.ByteCode
691+
// ByteCode forClass clazz bytes
692+
val bytes = {
693+
import scala.language.{reflectiveCalls, existentials}
694+
type ByteCode = { def bytes: Array[Byte] }
695+
type ByteCodeModule = { def forClass(clazz: Class[_]): ByteCode }
696+
val ByteCode = {
697+
val ByteCodeModuleCls =
698+
// RC1 package structure -- see: scala/scala#3588 and https://issues.scala-lang.org/browse/SI-8345
699+
(util.Try { Class.forName("scala.tools.scalap.scalax.rules.scalasig.ByteCode$") }
700+
// M8 package structure
701+
getOrElse Class.forName("scala.tools.scalap.scalasig.ByteCode$"))
702+
ByteCodeModuleCls.getDeclaredFields()(0).get(null).asInstanceOf[ByteCodeModule]
703+
}
704+
ByteCode forClass clazz bytes
705+
}
706+
707+
scalap.Main.decompileScala(bytes, isPackageObject)
708+
}
709+
686710
def runScalapTest() = runTestCommon {
687711
val isPackageObject = testFile.getName startsWith "package"
688712
val className = testFile.getName.stripSuffix(".scala").capitalize + (if (!isPackageObject) "" else ".package")
689713
val loader = ScalaClassLoader.fromURLs(List(outDir.toURI.toURL), this.getClass.getClassLoader)
690-
val byteCode = ByteCode forClass (loader loadClass className)
691-
val result = decompileScala(byteCode.bytes, isPackageObject)
692-
693-
logFile writeAll result
714+
logFile writeAll decompileClass(loader loadClass className, isPackageObject)
694715
diffIsOk
695716
}
717+
696718
def runScriptTest() = {
697719
import scala.sys.process._
698720
val (swr, wr) = newTestWriters()

0 commit comments

Comments
 (0)