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 923db8829..aac54a622 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 @@ -151,10 +151,10 @@ class ResolveReflectEval(using exprCtx: ExpressionContext) extends MiniPhase: case _ => tree def boxIfValueClass(term: TermSymbol, tree: Tree): Tree = - atPhase(Phases.elimErasedValueTypePhase)(term.info) match - case tpe: ErasedValueType => - boxValueClass(tpe.tycon.typeSymbol.asClass, tree) - case tpe => tree + getErasedValueType(atPhase(Phases.elimErasedValueTypePhase)(term.info)) match + case Some(erasedValueType) => + boxValueClass(erasedValueType.tycon.typeSymbol.asClass, tree) + case None => tree def boxValueClass(valueClass: ClassSymbol, tree: Tree): Tree = // qualifier is null: a value class cannot be nested into a class @@ -162,9 +162,14 @@ class ResolveReflectEval(using exprCtx: ExpressionContext) extends MiniPhase: callConstructor(nullLiteral, ctor, List(tree)) def unboxIfValueClass(term: TermSymbol, tree: Tree): Tree = - atPhase(Phases.elimErasedValueTypePhase)(term.info) match - case tpe: ErasedValueType => unboxValueClass(tree, tpe) - case tpe => tree + getErasedValueType(atPhase(Phases.elimErasedValueTypePhase)(term.info)) match + case Some(erasedValueType) => unboxValueClass(tree, erasedValueType) + case None => tree + + private def getErasedValueType(tpe: Type): Option[ErasedValueType] = tpe match + case tpe: ErasedValueType => Some(tpe) + case tpe: MethodOrPoly => getErasedValueType(tpe.resultType) + case tpe => None private def unboxValueClass(tree: Tree, tpe: ErasedValueType): Tree = val cls = tpe.tycon.typeSymbol.asClass 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 7efe16dae..76220e487 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 @@ -2011,6 +2011,33 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes // a pure expression does nothing in statement position check(Breakpoint(8), Evaluation.successOrIgnore("m", 1, ignore = isScala2)) } + + test("i425") { + val source = + """|package example + | + |object Rewrites { + | private class Patch(var span: Span) + | + | def main(args: Array[String]): Unit = { + | val patch = new Patch(new Span(0)) + | println("ok") + | } + |} + | + |class Span(val start: Int) extends AnyVal { + | def end = start + 1 + |} + |""".stripMargin + implicit val debuggee: TestingDebuggee = + TestingDebuggee.mainClass(source, "example.Rewrites", scalaVersion) + check( + Breakpoint(8), + Evaluation.success("patch.span", 0), + Evaluation.success("patch.span = new Span(1)", ()), + Evaluation.success("patch.span", 1) + ) + } } abstract class Scala2EvaluationTests(val scalaVersion: ScalaVersion) extends ScalaEvaluationTests(scalaVersion) {