From 47fddc713d3c2aa92c2df3e076f674aa667731ac Mon Sep 17 00:00:00 2001 From: Adrien Piquerez Date: Mon, 22 Jan 2024 15:40:00 +0100 Subject: [PATCH 1/4] Add support for Scala 3.4 --- build.sbt | 33 +++++++++++-------- .../scala/debugadapter/ScalaVersion.scala | 3 +- .../debugadapter/internal/DebugTools.scala | 2 +- .../tools/dotc/evaluation/SymUtils.scala | 9 +++++ .../dotty/tools/dotc/ExpressionCompiler.scala | 0 .../dotty/tools/dotc/ExpressionReporter.scala | 0 .../tools/dotc/evaluation/SymUtils.scala | 9 +++++ .../dotty/tools/dotc/ExpressionCompiler.scala | 17 ++++++++++ .../dotty/tools/dotc/ExpressionReporter.scala | 17 ++++++++++ .../tools/dotc/evaluation/SymUtils.scala | 3 ++ .../dotty/tools/dotc/ExpressionContext.scala | 2 +- .../dotc/evaluation/ExtractExpression.scala | 2 +- .../dotc/evaluation/ResolveReflectEval.scala | 2 +- .../ScalaStepFilterBridgeTests.scala | 4 +-- .../BypassExpressionCompilerTests.scala | 2 +- .../scala/debugadapter/ScalaDebugTests.scala | 2 +- .../debugadapter/ScalaEvaluationTests.scala | 8 ++--- .../debugadapter/SourceBreakpointTests.scala | 2 +- .../scala/debugadapter/StepFilterTests.scala | 2 +- project/Dependencies.scala | 7 ++-- 20 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 modules/expression-compiler/src/main/scala-3.0/dotty/tools/dotc/evaluation/SymUtils.scala rename modules/expression-compiler/src/main/{scala-3.1+ => scala-3.3}/dotty/tools/dotc/ExpressionCompiler.scala (100%) rename modules/expression-compiler/src/main/{scala-3.1+ => scala-3.3}/dotty/tools/dotc/ExpressionReporter.scala (100%) create mode 100644 modules/expression-compiler/src/main/scala-3.3/dotty/tools/dotc/evaluation/SymUtils.scala create mode 100644 modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/ExpressionCompiler.scala create mode 100644 modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/ExpressionReporter.scala create mode 100644 modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/evaluation/SymUtils.scala diff --git a/build.sbt b/build.sbt index 227108ce2..c60ae185e 100644 --- a/build.sbt +++ b/build.sbt @@ -34,7 +34,8 @@ lazy val root = project expressionCompiler212, expressionCompiler213, expressionCompiler30, - expressionCompiler3, + expressionCompiler33, + expressionCompiler34, scala3StepFilter ) .settings( @@ -68,7 +69,7 @@ lazy val core213 = core.jvm(Dependencies.scala213) lazy val core = projectMatrix .in(file("modules/core")) .jvmPlatform( - Seq(Dependencies.scala212, Dependencies.scala213, Dependencies.scala31Plus), + Seq(Dependencies.scala212, Dependencies.scala213, Dependencies.scala33), Seq.empty, p => p.dependsOn(javaDebug) ) @@ -95,16 +96,17 @@ lazy val core = projectMatrix BuildInfoKey.action("scala212")(Dependencies.scala212), BuildInfoKey.action("scala213")(Dependencies.scala213), BuildInfoKey.action("scala30")(Dependencies.scala30), - BuildInfoKey.action("scala31Plus")(Dependencies.scala31Plus) + BuildInfoKey.action("scala33")(Dependencies.scala33), + BuildInfoKey.action("scala34")(Dependencies.scala34) ), buildInfoPackage := "ch.epfl.scala.debugadapter" ) lazy val tests212 = tests.jvm(Dependencies.scala212) -lazy val tests3 = tests.jvm(Dependencies.scala31Plus) +lazy val tests3 = tests.jvm(Dependencies.scala33) lazy val tests = projectMatrix .in(file("modules/tests")) - .jvmPlatform(scalaVersions = Seq(Dependencies.scala212, Dependencies.scala213, Dependencies.scala31Plus)) + .jvmPlatform(scalaVersions = Seq(Dependencies.scala212, Dependencies.scala213, Dependencies.scala33)) .settings( name := "scala-debug-adapter-test", libraryDependencies ++= Seq( @@ -124,8 +126,8 @@ lazy val tests = projectMatrix .dependsOn( expressionCompiler212 / publishLocal, expressionCompiler213 / publishLocal, - expressionCompiler30 / publishLocal, - expressionCompiler3 / publishLocal, + expressionCompiler33 / publishLocal, + expressionCompiler34 / publishLocal, // break cyclic reference LocalProject("scala3StepFilter") / publishLocal ) @@ -154,13 +156,15 @@ lazy val sbtPlugin = project lazy val expressionCompiler212 = expressionCompiler.finder(scala212Axis)(true) lazy val expressionCompiler213 = expressionCompiler.finder(scala213Axis)(true) lazy val expressionCompiler30 = expressionCompiler.finder(scala30Axis)(true) -lazy val expressionCompiler3 = expressionCompiler.finder(scala3Axis)(true) +lazy val expressionCompiler33 = expressionCompiler.finder(scala33Axis)(true) +lazy val expressionCompiler34 = expressionCompiler.finder(scala34Axis)(true) lazy val expressionCompiler = projectMatrix .in(file("modules/expression-compiler")) .customRow(true, Seq(scala212Axis, VirtualAxis.jvm), identity[Project] _) .customRow(true, Seq(scala213Axis, VirtualAxis.jvm), identity[Project] _) .customRow(true, Seq(scala30Axis, VirtualAxis.jvm), identity[Project] _) - .customRow(true, Seq(scala3Axis, VirtualAxis.jvm), identity[Project] _) + .customRow(true, Seq(scala33Axis, VirtualAxis.jvm), identity[Project] _) + .customRow(true, Seq(scala34Axis, VirtualAxis.jvm), identity[Project] _) .settings( name := "scala-expression-compiler", crossScalaVersions ++= CrossVersion @@ -169,7 +173,8 @@ lazy val expressionCompiler = projectMatrix case (2, 12) => Seq("2.12.18", "2.12.17", "2.12.16", "2.12.15", "2.12.14", "2.12.13", "2.12.12", "2.12.11") case (2, 13) => Seq("2.13.11", "2.13.10", "2.13.9", "2.13.8", "2.13.7", "2.13.6", "2.13.5", "2.13.4", "2.13.3") case (3, 0) => Seq("3.0.2", "3.0.1", "3.0.0") - case (3, _) => Seq("3.3.1", "3.3.0", "3.2.2", "3.2.1", "3.2.0", "3.1.3", "3.1.2", "3.1.1", "3.1.0") + case (3, 1 | 2 | 3) => Seq("3.3.1", "3.3.0", "3.2.2", "3.2.1", "3.2.0", "3.1.3", "3.1.2", "3.1.1", "3.1.0") + case (3, _) => Seq("3.4.0-RC2") } .toSeq .flatten, @@ -185,7 +190,8 @@ lazy val expressionCompiler = projectMatrix val sourceDir = (Compile / sourceDirectory).value CrossVersion.partialVersion(scalaVersion.value).collect { case (3, 0) => sourceDir / s"scala-3.0" - case (3, minor) => sourceDir / s"scala-3.1+" + case (3, 1 | 2 | 3) => sourceDir / s"scala-3.3" + case (3, 4) => sourceDir / s"scala-3.4" } }, Compile / doc / sources := Seq.empty, @@ -199,7 +205,7 @@ lazy val scala3StepFilter: Project = project .dependsOn(tests3 % Test) .settings( name := "scala-debug-step-filter", - scalaVersion := Dependencies.scala31Plus, + scalaVersion := Dependencies.scala33, Compile / doc / sources := Seq.empty, libraryDependencies ++= Seq( "ch.epfl.scala" %% "tasty-query" % "0.9.3", @@ -221,7 +227,8 @@ lazy val scalacOptionsSetting = Def.settings( lazy val scala212Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala212, "2_12") lazy val scala213Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala213, "2_13") lazy val scala30Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala30, "3_0") -lazy val scala3Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala31Plus, "3") +lazy val scala33Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala33, "3_3") +lazy val scala34Axis = VirtualAxis.ScalaVersionAxis(Dependencies.scala34, "3_4") def onScalaVersion[T](scala212: T, scala213: T, scala3: T) = Def.setting { CrossVersion.partialVersion(scalaVersion.value) match { diff --git a/modules/core/src/main/scala/ch/epfl/scala/debugadapter/ScalaVersion.scala b/modules/core/src/main/scala/ch/epfl/scala/debugadapter/ScalaVersion.scala index a422b138a..2e458e0f2 100644 --- a/modules/core/src/main/scala/ch/epfl/scala/debugadapter/ScalaVersion.scala +++ b/modules/core/src/main/scala/ch/epfl/scala/debugadapter/ScalaVersion.scala @@ -20,5 +20,6 @@ object ScalaVersion { val `2.12` = ScalaVersion(BuildInfo.scala212) val `2.13` = ScalaVersion(BuildInfo.scala213) val `3.0` = ScalaVersion(BuildInfo.scala30) - val `3.1+` = ScalaVersion(BuildInfo.scala31Plus) + val `3.3` = ScalaVersion(BuildInfo.scala33) + val `3.4` = ScalaVersion(BuildInfo.scala34) } diff --git a/modules/core/src/main/scala/ch/epfl/scala/debugadapter/internal/DebugTools.scala b/modules/core/src/main/scala/ch/epfl/scala/debugadapter/internal/DebugTools.scala index b84391f58..38c772b58 100644 --- a/modules/core/src/main/scala/ch/epfl/scala/debugadapter/internal/DebugTools.scala +++ b/modules/core/src/main/scala/ch/epfl/scala/debugadapter/internal/DebugTools.scala @@ -88,7 +88,7 @@ object DebugTools { debuggee.libraries .find(_.artifactId.startsWith("scala3-library")) .map(lib => ScalaVersion(lib.version)) - .getOrElse(ScalaVersion.`3.1+`) + .getOrElse(ScalaVersion.`3.3`) def resolveCompilerClassLoader(scalaVersion: ScalaVersion): Option[ClassLoader] = resolver diff --git a/modules/expression-compiler/src/main/scala-3.0/dotty/tools/dotc/evaluation/SymUtils.scala b/modules/expression-compiler/src/main/scala-3.0/dotty/tools/dotc/evaluation/SymUtils.scala new file mode 100644 index 000000000..6c2dfb737 --- /dev/null +++ b/modules/expression-compiler/src/main/scala-3.0/dotty/tools/dotc/evaluation/SymUtils.scala @@ -0,0 +1,9 @@ +package dotty.tools.dotc.evaluation + +import dotty.tools.dotc.core.Contexts.Context +import dotty.tools.dotc.core.Symbols.Symbol + +object SymUtils: + export dotty.tools.dotc.transform.SymUtils.{isLocal => _, enclosingMethodOrClass => _, *} + + extension (self: Symbol) def isLocal(using Context) = dotty.tools.dotc.transform.SymUtils.isLocal(self) diff --git a/modules/expression-compiler/src/main/scala-3.1+/dotty/tools/dotc/ExpressionCompiler.scala b/modules/expression-compiler/src/main/scala-3.3/dotty/tools/dotc/ExpressionCompiler.scala similarity index 100% rename from modules/expression-compiler/src/main/scala-3.1+/dotty/tools/dotc/ExpressionCompiler.scala rename to modules/expression-compiler/src/main/scala-3.3/dotty/tools/dotc/ExpressionCompiler.scala diff --git a/modules/expression-compiler/src/main/scala-3.1+/dotty/tools/dotc/ExpressionReporter.scala b/modules/expression-compiler/src/main/scala-3.3/dotty/tools/dotc/ExpressionReporter.scala similarity index 100% rename from modules/expression-compiler/src/main/scala-3.1+/dotty/tools/dotc/ExpressionReporter.scala rename to modules/expression-compiler/src/main/scala-3.3/dotty/tools/dotc/ExpressionReporter.scala diff --git a/modules/expression-compiler/src/main/scala-3.3/dotty/tools/dotc/evaluation/SymUtils.scala b/modules/expression-compiler/src/main/scala-3.3/dotty/tools/dotc/evaluation/SymUtils.scala new file mode 100644 index 000000000..6c2dfb737 --- /dev/null +++ b/modules/expression-compiler/src/main/scala-3.3/dotty/tools/dotc/evaluation/SymUtils.scala @@ -0,0 +1,9 @@ +package dotty.tools.dotc.evaluation + +import dotty.tools.dotc.core.Contexts.Context +import dotty.tools.dotc.core.Symbols.Symbol + +object SymUtils: + export dotty.tools.dotc.transform.SymUtils.{isLocal => _, enclosingMethodOrClass => _, *} + + extension (self: Symbol) def isLocal(using Context) = dotty.tools.dotc.transform.SymUtils.isLocal(self) diff --git a/modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/ExpressionCompiler.scala b/modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/ExpressionCompiler.scala new file mode 100644 index 000000000..e54e03883 --- /dev/null +++ b/modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/ExpressionCompiler.scala @@ -0,0 +1,17 @@ +package dotty.tools.dotc + +import dotty.tools.dotc.core.Contexts.Context +import dotty.tools.dotc.core.Phases.Phase +import dotty.tools.dotc.evaluation.* + +class ExpressionCompiler(using ExpressionContext)(using Context) extends Compiler: + + override protected def frontendPhases: List[List[Phase]] = + val parser :: others = super.frontendPhases: @unchecked + parser :: List(InsertExpression()) :: others + + override protected def picklerPhases: List[List[Phase]] = + super.picklerPhases :+ List(ExtractExpression()) + + override protected def transformPhases: List[List[Phase]] = + super.transformPhases :+ List(ResolveReflectEval()) diff --git a/modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/ExpressionReporter.scala b/modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/ExpressionReporter.scala new file mode 100644 index 000000000..1ef9df7a0 --- /dev/null +++ b/modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/ExpressionReporter.scala @@ -0,0 +1,17 @@ +package dotty.tools.dotc + +import dotty.tools.dotc.core.Contexts.* +import dotty.tools.dotc.reporting.AbstractReporter +import dotty.tools.dotc.reporting.Diagnostic + +class ExpressionReporter(reportError: String => Unit) extends AbstractReporter: + override def doReport(dia: Diagnostic)(using Context): Unit = + // println(messageAndPos(dia)) + dia match + case error: Diagnostic.Error => + val newPos = error.pos.source.positionInUltimateSource(error.pos) + val errorWithNewPos = new Diagnostic.Error(error.msg, newPos) + reportError(stripColor(messageAndPos(errorWithNewPos))) + case _ => + // TODO report the warnings + () diff --git a/modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/evaluation/SymUtils.scala b/modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/evaluation/SymUtils.scala new file mode 100644 index 000000000..4168428f7 --- /dev/null +++ b/modules/expression-compiler/src/main/scala-3.4/dotty/tools/dotc/evaluation/SymUtils.scala @@ -0,0 +1,3 @@ +package dotty.tools.dotc.evaluation + +object SymUtils extends dotty.tools.dotc.core.SymUtils diff --git a/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/ExpressionContext.scala b/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/ExpressionContext.scala index b460abac9..fbac778c9 100644 --- a/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/ExpressionContext.scala +++ b/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/ExpressionContext.scala @@ -6,7 +6,7 @@ import dotty.tools.dotc.core.Types.* import dotty.tools.dotc.core.Names.* import dotty.tools.dotc.core.Flags.* import dotty.tools.dotc.core.Contexts.* -import dotty.tools.dotc.transform.SymUtils.* +import dotty.tools.dotc.evaluation.SymUtils.* class ExpressionContext( uniqueName: String, diff --git a/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ExtractExpression.scala b/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ExtractExpression.scala index 4d661a3bf..850b0be55 100644 --- a/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ExtractExpression.scala +++ b/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ExtractExpression.scala @@ -8,10 +8,10 @@ import dotty.tools.dotc.core.Flags.* import dotty.tools.dotc.core.Names.* import dotty.tools.dotc.core.Symbols.* import dotty.tools.dotc.core.Types.* -import dotty.tools.dotc.transform.SymUtils.* import dotty.tools.dotc.core.DenotTransformers.DenotTransformer import dotty.tools.dotc.core.Denotations.SingleDenotation import dotty.tools.dotc.core.SymDenotations.SymDenotation +import dotty.tools.dotc.evaluation.SymUtils.* import dotty.tools.dotc.transform.MacroTransform import dotty.tools.dotc.core.Phases.* import dotty.tools.dotc.report diff --git a/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ResolveReflectEval.scala b/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ResolveReflectEval.scala index 07924b49d..6820282ea 100644 --- a/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ResolveReflectEval.scala +++ b/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ResolveReflectEval.scala @@ -9,9 +9,9 @@ import dotty.tools.dotc.core.Names.* import dotty.tools.dotc.core.Symbols.* import dotty.tools.dotc.core.Types.* import dotty.tools.dotc.transform.MegaPhase.MiniPhase -import dotty.tools.dotc.transform.SymUtils.* import dotty.tools.dotc.core.StdNames.* import dotty.tools.dotc.core.NameKinds.QualifiedInfo +import dotty.tools.dotc.evaluation.SymUtils.* import dotty.tools.dotc.report import dotty.tools.dotc.core.Phases import dotty.tools.dotc.core.TypeErasure.ErasedValueType diff --git a/modules/scala-3-step-filter/src/test/scala/ch/epfl/scala/debugadapter/internal/stepfilter/ScalaStepFilterBridgeTests.scala b/modules/scala-3-step-filter/src/test/scala/ch/epfl/scala/debugadapter/internal/stepfilter/ScalaStepFilterBridgeTests.scala index 3cc61ec85..d0c67fb8a 100644 --- a/modules/scala-3-step-filter/src/test/scala/ch/epfl/scala/debugadapter/internal/stepfilter/ScalaStepFilterBridgeTests.scala +++ b/modules/scala-3-step-filter/src/test/scala/ch/epfl/scala/debugadapter/internal/stepfilter/ScalaStepFilterBridgeTests.scala @@ -15,8 +15,8 @@ import tastyquery.Symbols.TermSymbol import java.{util => ju} -class Scala30StepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.0`) -class Scala31PlusStepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.1+`) +class Scala33StepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.3`) +class Scala34StepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.4`) abstract class ScalaStepFilterBridgeTests(scalaVersion: ScalaVersion) extends FunSuite: test("mixin-forwarders") { diff --git a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/BypassExpressionCompilerTests.scala b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/BypassExpressionCompilerTests.scala index 2af7a7556..ca3036e6d 100644 --- a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/BypassExpressionCompilerTests.scala +++ b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/BypassExpressionCompilerTests.scala @@ -3,7 +3,7 @@ package ch.epfl.scala.debugadapter import ch.epfl.scala.debugadapter.testfmk.* class BypassExpressionCompilerTests extends DebugTestSuite { - private val scalaVersion = ScalaVersion.`3.1+` + private val scalaVersion = ScalaVersion.`3.3` protected override def defaultConfig: DebugConfig = super.defaultConfig.copy(evaluationMode = DebugConfig.SimpleEvaluationOnly) diff --git a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaDebugTests.scala b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaDebugTests.scala index 376f53519..0b6e484e5 100644 --- a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaDebugTests.scala +++ b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaDebugTests.scala @@ -6,7 +6,7 @@ import scala.concurrent.duration._ class Scala212DebugTest extends ScalaDebugTests(ScalaVersion.`2.12`) class Scala213DebugTest extends ScalaDebugTests(ScalaVersion.`2.13`) -class Scala3DebugTest extends ScalaDebugTests(ScalaVersion.`3.1+`) { +class Scala33DebugTest extends ScalaDebugTests(ScalaVersion.`3.3`) { test("should support breakpoints in scala 3 with brace-less syntax") { val source = """|package example diff --git a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala index 591e02e27..8f5f55b63 100644 --- a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala +++ b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala @@ -4,7 +4,7 @@ import ch.epfl.scala.debugadapter.testfmk.* class Scala212EvaluationTests extends Scala2EvaluationTests(ScalaVersion.`2.12`) class Scala213EvaluationTests extends Scala2EvaluationTests(ScalaVersion.`2.13`) { - if (ScalaVersion.`3.1+`.isRelease) { + if (ScalaVersion.`3.3`.isRelease) { test("should use tasty-reader") { val scala2Source = """|package example @@ -33,7 +33,7 @@ class Scala213EvaluationTests extends Scala2EvaluationTests(ScalaVersion.`2.13`) implicit val debuggee: TestingDebuggee = TestingDebuggee.mainClass( scala3Source, "example.Main", - ScalaVersion.`3.1+`, + ScalaVersion.`3.3`, Seq.empty, Seq(scala2Debugee.mainModule) ) @@ -44,8 +44,8 @@ class Scala213EvaluationTests extends Scala2EvaluationTests(ScalaVersion.`2.13`) } } } -class Scala30EvaluationTests extends Scala3EvaluationTests(ScalaVersion.`3.0`) -class Scala31PlusEvaluationTests extends Scala3EvaluationTests(ScalaVersion.`3.1+`) +class Scala33EvaluationTests extends Scala3EvaluationTests(ScalaVersion.`3.3`) +class Scala34EvaluationTests extends Scala3EvaluationTests(ScalaVersion.`3.4`) abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTestSuite { protected override def defaultConfig: DebugConfig = diff --git a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/SourceBreakpointTests.scala b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/SourceBreakpointTests.scala index de0f3399b..91beaf43f 100644 --- a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/SourceBreakpointTests.scala +++ b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/SourceBreakpointTests.scala @@ -3,7 +3,7 @@ package ch.epfl.scala.debugadapter import ch.epfl.scala.debugadapter.testfmk.* class Scala213SourceBreakpointTests extends SourceBreakpointTests(ScalaVersion.`2.13`) -class Scala3SourceBreakpointTests extends SourceBreakpointTests(ScalaVersion.`3.1+`) +class Scala3SourceBreakpointTests extends SourceBreakpointTests(ScalaVersion.`3.3`) abstract class SourceBreakpointTests(scalaVersion: ScalaVersion) extends DebugTestSuite { test("evaluate simple breakpoint") { diff --git a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/StepFilterTests.scala b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/StepFilterTests.scala index 9c7aa928f..db5879ff9 100644 --- a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/StepFilterTests.scala +++ b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/StepFilterTests.scala @@ -2,7 +2,7 @@ package ch.epfl.scala.debugadapter import ch.epfl.scala.debugadapter.testfmk.* -class Scala3StepFilterTests extends StepFilterTests(ScalaVersion.`3.1+`) { +class Scala3StepFilterTests extends StepFilterTests(ScalaVersion.`3.3`) { test("step into method with @targetName") { val source = """|package example diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 877a7f25c..8b1ec33bf 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -5,14 +5,17 @@ object Dependencies { val scala212 = scalaEnvVersion.filter(isScala212).getOrElse("2.12.18") val scala213 = scalaEnvVersion.filter(isScala213).getOrElse("2.13.11") val scala30 = scalaEnvVersion.filter(isScala30).getOrElse("3.0.2") - val scala31Plus = scalaEnvVersion.filter(isScala31Plus).getOrElse("3.3.1") + val scala33 = scalaEnvVersion.filter(isScala33).getOrElse("3.3.1") + val scala34 = scalaEnvVersion.filter(isScala34).getOrElse("3.4.0-RC2") val asmVersion = "9.5" val coursierVersion = "2.1.5" def isScala212(version: String): Boolean = version.startsWith("2.12") def isScala213(version: String): Boolean = version.startsWith("2.13") def isScala30(version: String): Boolean = version.startsWith("3.0") - def isScala31Plus(version: String): Boolean = version.startsWith("3") && !isScala30(version) + def isScala33(version: String): Boolean = + version.startsWith("3.1") || version.startsWith("3.2") || version.startsWith("3.3") + def isScala34(version: String): Boolean = version.startsWith("3") && !isScala30(version) && !isScala33(version) val asm = "org.ow2.asm" % "asm" % asmVersion val asmUtil = "org.ow2.asm" % "asm-util" % asmVersion From 4c84bbcbdf78a97f322c1706cdd109cd8af508d0 Mon Sep 17 00:00:00 2001 From: Adrien Piquerez Date: Mon, 22 Jan 2024 16:58:06 +0100 Subject: [PATCH 2/4] Fix tests --- .../dotc/evaluation/ResolveReflectEval.scala | 3 +++ .../debugadapter/testfmk/DebugStepAssert.scala | 6 +++--- .../debugadapter/ScalaEvaluationTests.scala | 8 ++++---- .../internal/MetalsClassBreakpointSuite.scala | 18 ++++++------------ 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ResolveReflectEval.scala b/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ResolveReflectEval.scala index 6820282ea..d0c028bc3 100644 --- a/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ResolveReflectEval.scala +++ b/modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/ResolveReflectEval.scala @@ -47,6 +47,9 @@ class ResolveReflectEval(using exprCtx: ExpressionContext) extends MiniPhase: // if cls is a value class then the local $this is the erased value, // but we expect an instance of the value class instead gen.boxValueClass(cls, gen.getLocalValue("$this")) + else if cls.is(ModuleClass) && !exprCtx.localVariables.contains("$this") then + // in Scala 3.4: an anonfun in an object is static + gen.getStaticObject(cls) else gen.getLocalValue("$this") case EvaluationStrategy.LocalOuter(cls) => gen.getLocalValue("$outer") diff --git a/modules/tests/src/main/scala/ch/epfl/scala/debugadapter/testfmk/DebugStepAssert.scala b/modules/tests/src/main/scala/ch/epfl/scala/debugadapter/testfmk/DebugStepAssert.scala index 789de2703..73b39c475 100644 --- a/modules/tests/src/main/scala/ch/epfl/scala/debugadapter/testfmk/DebugStepAssert.scala +++ b/modules/tests/src/main/scala/ch/epfl/scala/debugadapter/testfmk/DebugStepAssert.scala @@ -34,15 +34,15 @@ object DebugStepAssert { assertEquals(frame.line, expectedLine) } - def assertOnFrame(expectedName: String)(frame: StackFrame): Unit = + def assertOnFrame(expectedName: String)(frame: StackFrame)(implicit location: Location): Unit = assertEquals(frame.name, expectedName) } object Breakpoint { - def apply(line: Int)(implicit ctx: TestingContext): SingleStepAssert[StackFrame] = + def apply(line: Int)(implicit ctx: TestingContext, location: Location): SingleStepAssert[StackFrame] = Breakpoint(ctx.mainSource, line) - def apply(sourceFile: Path, line: Int): SingleStepAssert[StackFrame] = { + def apply(sourceFile: Path, line: Int)(implicit location: Location): SingleStepAssert[StackFrame] = { val breakpoint = Breakpoint(sourceFile, line, None) SingleStepAssert(breakpoint, assertOnFrame(sourceFile, line)) } diff --git a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala index 8f5f55b63..e696df02e 100644 --- a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala +++ b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala @@ -2303,7 +2303,7 @@ abstract class Scala3EvaluationTests(scalaVersion: ScalaVersion) extends ScalaEv |""".stripMargin implicit val debuggee: TestingDebuggee = TestingDebuggee.mainClass(source, "example.Main", scalaVersion) check( - Breakpoint(8), // Stops once in the constructor of B + if (isScala33) Breakpoint(8) else NoStep(), // Stops once in the constructor of B Breakpoint(8), Evaluation.success("x1 + x2 + x3", "x1x2x3") ) @@ -2552,9 +2552,9 @@ abstract class Scala3EvaluationTests(scalaVersion: ScalaVersion) extends ScalaEv implicit val debuggee: TestingDebuggee = TestingDebuggee.mainClass(source, "example.Main", scalaVersion) check( Breakpoint(12), - Breakpoint(12), - Breakpoint(15), - Breakpoint(20), // in A#m + if (isScala33) Breakpoint(12) else NoStep(), + if (isScala33) Breakpoint(15) else NoStep(), + Breakpoint(20), DebugStepAssert.inParallel(Evaluation.success("A.A1.a", 1), Evaluation.success("A.A2.a", 2)), Breakpoint(15), DebugStepAssert.inParallel( diff --git a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/internal/MetalsClassBreakpointSuite.scala b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/internal/MetalsClassBreakpointSuite.scala index 48e50d1d8..7f8c1934f 100644 --- a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/internal/MetalsClassBreakpointSuite.scala +++ b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/internal/MetalsClassBreakpointSuite.scala @@ -122,7 +122,7 @@ class MetalsClassBreakpointSuite extends FunSuite { |} |""".stripMargin, "a.b.Main$package$", - scalaVersion = ScalaVersion.`3.0` + scalaVersion = ScalaVersion.`3.3` ) } @@ -136,10 +136,9 @@ class MetalsClassBreakpointSuite extends FunSuite { |>> def unapply(s: String): Boolean = s.size % 2 == 0 | } |} - | |""".stripMargin, - "a.Main$package$Even$1$", - scalaVersion = ScalaVersion.`3.0` + "a.Main$package$Even$2$", + scalaVersion = ScalaVersion.`3.3` ) } @@ -159,7 +158,7 @@ class MetalsClassBreakpointSuite extends FunSuite { | |""".stripMargin, "a.Main$package$", - scalaVersion = ScalaVersion.`3.0` + scalaVersion = ScalaVersion.`3.3` ) } @@ -169,16 +168,11 @@ class MetalsClassBreakpointSuite extends FunSuite { scalaVersion: ScalaVersion = ScalaVersion.`2.13` ): Unit = { val source = original.replace(">>", " ") - val lineNumber = - original.linesIterator.toSeq.indexWhere(_.contains(">>")) + 1 - + val lineNumber = original.linesIterator.toSeq.indexWhere(_.contains(">>")) + 1 val debuggee = TestingDebuggee.mainClass(source, "Main", scalaVersion) val lookUp = ClassEntryLookUp(debuggee.mainModule, NoopLogger) - val sourceFileKey = SourceFileKey(debuggee.sourceFiles.head.toUri) - - val className = - lookUp.getFullyQualifiedClassName(sourceFileKey, lineNumber) + val className = lookUp.getFullyQualifiedClassName(sourceFileKey, lineNumber) assert(className.contains(expectedClassName)) } } From 64f6b866c7452847fefe08fe53096b82e6f13a31 Mon Sep 17 00:00:00 2001 From: Adrien Piquerez Date: Tue, 23 Jan 2024 10:48:08 +0100 Subject: [PATCH 3/4] Ignore Scala34StepFilterBridgeTests temporarily --- .../internal/stepfilter/ScalaStepFilterBridgeTests.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/scala-3-step-filter/src/test/scala/ch/epfl/scala/debugadapter/internal/stepfilter/ScalaStepFilterBridgeTests.scala b/modules/scala-3-step-filter/src/test/scala/ch/epfl/scala/debugadapter/internal/stepfilter/ScalaStepFilterBridgeTests.scala index d0c67fb8a..de15ffd53 100644 --- a/modules/scala-3-step-filter/src/test/scala/ch/epfl/scala/debugadapter/internal/stepfilter/ScalaStepFilterBridgeTests.scala +++ b/modules/scala-3-step-filter/src/test/scala/ch/epfl/scala/debugadapter/internal/stepfilter/ScalaStepFilterBridgeTests.scala @@ -16,7 +16,9 @@ import tastyquery.Symbols.TermSymbol import java.{util => ju} class Scala33StepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.3`) -class Scala34StepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.4`) +class Scala34StepFilterBridgeTests extends ScalaStepFilterBridgeTests(ScalaVersion.`3.4`): + // all tests fail because of the TASTy signature + override def munitIgnore: Boolean = true abstract class ScalaStepFilterBridgeTests(scalaVersion: ScalaVersion) extends FunSuite: test("mixin-forwarders") { From c2a3225a7a76895d34f469e2f18b9d97cfa29c3a Mon Sep 17 00:00:00 2001 From: Adrien Piquerez Date: Tue, 23 Jan 2024 10:59:49 +0100 Subject: [PATCH 4/4] cleanup --- .../scala/debugadapter/ScalaVersion.scala | 2 - .../debugadapter/testfmk/DebugTestSuite.scala | 2 - .../BypassExpressionCompilerTests.scala | 1 - .../debugadapter/ScalaEvaluationTests.scala | 40 ++++++------------- 4 files changed, 13 insertions(+), 32 deletions(-) diff --git a/modules/core/src/main/scala/ch/epfl/scala/debugadapter/ScalaVersion.scala b/modules/core/src/main/scala/ch/epfl/scala/debugadapter/ScalaVersion.scala index 2e458e0f2..261f268d8 100644 --- a/modules/core/src/main/scala/ch/epfl/scala/debugadapter/ScalaVersion.scala +++ b/modules/core/src/main/scala/ch/epfl/scala/debugadapter/ScalaVersion.scala @@ -5,8 +5,6 @@ case class ScalaVersion(value: String) { def isScala3: Boolean = value.startsWith("3") def isScala212: Boolean = value.startsWith("2.12") def isScala213: Boolean = value.startsWith("2.13") - def isScala30: Boolean = value.startsWith("3.0") - def isScala31Plus: Boolean = value.startsWith("3") && !isScala30 def isScala33: Boolean = value.startsWith("3.3") def binaryVersion: String = if (isScala3) "3" else if (isScala213) "2.13" else "2.12" diff --git a/modules/tests/src/main/scala/ch/epfl/scala/debugadapter/testfmk/DebugTestSuite.scala b/modules/tests/src/main/scala/ch/epfl/scala/debugadapter/testfmk/DebugTestSuite.scala index 679f0b696..a06822130 100644 --- a/modules/tests/src/main/scala/ch/epfl/scala/debugadapter/testfmk/DebugTestSuite.scala +++ b/modules/tests/src/main/scala/ch/epfl/scala/debugadapter/testfmk/DebugTestSuite.scala @@ -32,8 +32,6 @@ trait DebugTest { def isScala2(implicit ctx: TestingContext) = ctx.scalaVersion.isScala2 def isScala213(implicit ctx: TestingContext) = ctx.scalaVersion.isScala213 def isScala212(implicit ctx: TestingContext) = ctx.scalaVersion.isScala212 - def isScala30(implicit ctx: TestingContext) = ctx.scalaVersion.isScala30 - def isScala31Plus(implicit ctx: TestingContext) = ctx.scalaVersion.isScala31Plus def isScala33(implicit ctx: TestingContext) = ctx.scalaVersion.isScala33 def getDebugServer( diff --git a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/BypassExpressionCompilerTests.scala b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/BypassExpressionCompilerTests.scala index ca3036e6d..ffedb6de4 100644 --- a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/BypassExpressionCompilerTests.scala +++ b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/BypassExpressionCompilerTests.scala @@ -363,7 +363,6 @@ class BypassExpressionCompilerTests extends DebugTestSuite { } test("evaluate capture of pattern") { - assume(!scalaVersion.isScala30) // Won't be fixed in Scala 3.0 val source = """|package example | diff --git a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala index e696df02e..8d6fd742d 100644 --- a/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala +++ b/modules/tests/src/test/scala/ch/epfl/scala/debugadapter/ScalaEvaluationTests.scala @@ -556,10 +556,7 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes |} |""".stripMargin implicit val debuggee: TestingDebuggee = TestingDebuggee.mainClass(source, "example.Main", scalaVersion) - check( - Breakpoint(7), - Evaluation.success("a1", if (isScala3) new NoSuchFieldException("$outer") else new NoSuchFieldError("$outer")) - ) + check(Breakpoint(7), Evaluation.success("a1", noSuchFieldError)) } test("evaluate from an local class") { @@ -893,10 +890,7 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes Evaluation.success("x1", "x1"), // captured by B Evaluation.success("m()", "x1x2"), // captures x2 Evaluation.success("this.m()", "x1"), - Evaluation.success( - "A.this.m()", - if (isScala3) new NoSuchFieldException("$outer") else new NoSuchFieldError("$outer") - ), + Evaluation.success("A.this.m()", noSuchFieldError), Evaluation.successOrIgnore("new B", isScala2)(result => assert(result.startsWith("A$B$1@"))) ), // captures x1 Breakpoint(22), // in B#m#m @@ -1060,8 +1054,7 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes check( Breakpoint(7), Evaluation.successOrIgnore("x", 1, isScala2), - if (isScala3) Evaluation.failed("y") - else Evaluation.success("y", 2), + if (isScala3) Evaluation.failed("y") else Evaluation.success("y", 2), Evaluation.successOrIgnore( """|lazy val z = 2 |z""".stripMargin, @@ -1408,14 +1401,10 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes ), Breakpoint(6), DebugStepAssert.inParallel( - if (isScala3) Evaluation.failed("self", "not supported") - else Evaluation.success("self", "foo"), - if (isScala3) Evaluation.failed("size", "not supported") - else Evaluation.success("size", 2), - if (isScala3) Evaluation.failed("m(1)", "not supported") - else Evaluation.success("m(1)", "fo"), - if (isScala3) Evaluation.failed("this.m(1)", "not supported") - else Evaluation.success("this.m(1)", "ff") + if (isScala3) Evaluation.failed("self", "not supported") else Evaluation.success("self", "foo"), + if (isScala3) Evaluation.failed("size", "not supported") else Evaluation.success("size", 2), + if (isScala3) Evaluation.failed("m(1)", "not supported") else Evaluation.success("m(1)", "fo"), + if (isScala3) Evaluation.failed("this.m(1)", "not supported") else Evaluation.success("this.m(1)", "ff") ) ) } @@ -1503,12 +1492,7 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes |} |""".stripMargin implicit val debuggee: TestingDebuggee = TestingDebuggee.munitTestSuite(source, "example.MySuite", scalaVersion) - check( - Breakpoint(6), - // the program stops twice before Scala 3.2 - if (!isScala31Plus) Breakpoint(6) else NoStep(), - Evaluation.success("1 + 1", 2) - ) + check(Breakpoint(6), Evaluation.success("1 + 1", 2)) } test("evaluate lambdas") { @@ -1956,8 +1940,8 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes Breakpoint(8), // still in the same lifted lambda (the line position does not make any sense) Breakpoint(9), // again in the lifted lambda Breakpoint(8), // going out of the lifted lambda - if (isScala31Plus) Breakpoint(8) else NoStep(), // regression in Scala 3.2.2 - if (isScala31Plus) Breakpoint(9) else NoStep(), // regression in Scala 3.2.2 + Breakpoint(8), // regression in Scala 3.2.2 + Breakpoint(9), // regression in Scala 3.2.2 Breakpoint(13), // calling withFilter Breakpoint(13), Evaluation.success("x", 1), @@ -1992,7 +1976,6 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes } test("evaluate capture of pattern") { - assume(!scalaVersion.isScala30) // Won't be fixed in Scala 3.0 val source = """|package example | @@ -2171,6 +2154,9 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes ) ) } + + def noSuchFieldError(implicit ctx: TestingContext): Throwable = + if (isScala3) new NoSuchFieldException("$outer") else new NoSuchFieldError("$outer") } abstract class Scala2EvaluationTests(val scalaVersion: ScalaVersion) extends ScalaEvaluationTests(scalaVersion) {