-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #532 from adpi2/fix-eval-static-field
Evaluation of static members
- Loading branch information
Showing
7 changed files
with
154 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...compiler/src/test/scala-3.latest/ch/epfl/scala/debugadapter/ExpressionCompilerDebug.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package ch.epfl.scala.debugadapter | ||
|
||
import ch.epfl.scala.debugadapter.testfmk.TestingDebuggee | ||
import ch.epfl.scala.debugadapter.ScalaVersion | ||
import dotty.tools.dotc.ExpressionCompilerBridge | ||
import java.nio.file.Files | ||
import scala.collection.mutable.Buffer | ||
import java.{util => ju} | ||
import scala.jdk.CollectionConverters.* | ||
import scala.concurrent.duration.* | ||
|
||
/** | ||
* This class is used to enter the expression compiler with a debugger | ||
* It is not meant to be run in the CI | ||
*/ | ||
class ExpressionCompilerDebug extends munit.FunSuite: | ||
val scalaVersion = ScalaVersion.`3.1+` | ||
val compiler = new ExpressionCompilerBridge | ||
|
||
override def munitTimeout: Duration = 1.hour | ||
|
||
test("debug expression compiler".ignore) { | ||
val javaSource = | ||
"""|package example; | ||
| | ||
|class A { | ||
| protected static String x = "x"; | ||
| protected static String m() { | ||
| return "m"; | ||
| } | ||
|} | ||
|""".stripMargin | ||
val javaModule = TestingDebuggee.fromJavaSource(javaSource, "example.A", scalaVersion) | ||
val scalaSource = | ||
"""|package example | ||
| | ||
|object Main extends A { | ||
| def main(args: Array[String]): Unit = { | ||
| println("Hello, World!") | ||
| } | ||
|} | ||
|""".stripMargin | ||
implicit val debuggee: TestingDebuggee = | ||
TestingDebuggee.mainClass(scalaSource, "example.Main", scalaVersion, Seq.empty, Seq(javaModule.mainModule)) | ||
evaluate(5, "A.x") | ||
evaluate(5, "A.m") | ||
} | ||
|
||
def evaluate(line: Int, expression: String, localVariables: Set[String] = Set.empty)(using | ||
debuggee: TestingDebuggee | ||
): Unit = | ||
val out = debuggee.tempDir.resolve("expr-classes") | ||
if Files.notExists(out) then Files.createDirectory(out) | ||
val errors = Buffer.empty[String] | ||
compiler.run( | ||
out, | ||
"Expression", | ||
debuggee.classPathString, | ||
debuggee.mainModule.scalacOptions.toArray, | ||
debuggee.mainSource, | ||
line, | ||
expression, | ||
localVariables.asJava, | ||
"example", | ||
error => { | ||
println(Console.RED + error + Console.RESET) | ||
errors += error | ||
}, | ||
testMode = true | ||
) | ||
if errors.nonEmpty then throw new Exception("Evaluation failed") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters