Skip to content

Commit 1fb51b2

Browse files
committed
Woraround for scala/scala3#18816
1 parent 0a8bf69 commit 1fb51b2

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

modules/unpickler/src/main/scala/ch/epfl/scala/debugadapter/internal/stacktrace/Scala3Unpickler.scala

+10-2
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,11 @@ class Scala3Unpickler(
740740
if adapted then tpe.erasedAsReturnType.toString == "void"
741741
else method.returnType.forall(matchType(tpe.erasedAsReturnType, _))
742742
val classOwners = getOwners(binaryClass)
743-
val sourceSpan = removeInlinedLines(method.sourceLines, classOwners).interval
743+
val sourceSpan =
744+
if classOwners.size == 2 && method.allParameters.filter(p => p.name.matches("\\$this\\$\\d+")).nonEmpty then
745+
// workaround of https://github.com/lampepfl/dotty/issues/18816
746+
removeInlinedLines(method.sourceLines, classOwners).maxOption.toSeq
747+
else removeInlinedLines(method.sourceLines, classOwners)
744748
for
745749
classOwner <- classOwners
746750
byNameArg <- collectTrees1(classOwner, sourceSpan)(inlined => {
@@ -793,7 +797,11 @@ class Scala3Unpickler(
793797
matcher: Boolean => PartialFunction[TermSymbol, BinaryMethodSymbol]
794798
): Seq[BinaryMethodSymbol] =
795799
val owners = getOwners(binaryClass)
796-
val sourceLines = removeInlinedLines(javaMethod.sourceLines, owners)
800+
val sourceLines =
801+
if owners.size == 2 && javaMethod.allParameters.filter(p => p.name.matches("\\$this\\$\\d+")).nonEmpty then
802+
// workaround of https://github.com/lampepfl/dotty/issues/18816
803+
removeInlinedLines(javaMethod.sourceLines, owners).maxOption.toSeq
804+
else removeInlinedLines(javaMethod.sourceLines, owners)
797805
for
798806
owner <- owners
799807
term <- collectTrees1(owner, sourceLines) { inlined =>

modules/unpickler/src/test/scala/ch/epfl/scala/debugadapter/internal/stacktrace/Scala3UnpicklerStats.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ class Scala3UnpicklerStats extends munit.FunSuite:
5151

5252
for
5353
cls <- loadClasses(jars, "scala3-compiler_3-3.3.0", binaryClassLoader)
54-
// if cls.name == "dotty.tools.dotc.core.Types$TermLambda"
54+
// if cls.name == "dotty.tools.dotc.transform.ExplicitOuter$OuterOps$"
5555
clsSym <- cls match
5656
case Patterns.LocalClass(_, _, _) => unpickler.tryFind(cls, localClassCounter)
5757
case Patterns.AnonClass(_, _) => unpickler.tryFind(cls, anonClassCounter)
5858
case Patterns.InnerClass(_) => unpickler.tryFind(cls, innerClassCounter)
5959
case _ => unpickler.tryFind(cls, topLevelClassCounter)
6060
method <- cls.declaredMethods
61-
// if method.name == "dotty$tools$dotc$core$Types$TermLambda$$_$compute$1$"
61+
// if method.name == "path$extension$$anonfun$1"
6262
do
6363
method match
6464
case Patterns.AnonFun(_) => unpickler.tryFind(method, anonFunCounter)
6565
case Patterns.AdaptedAnonFun(_) => unpickler.tryFind(method, adaptedAnonFunCounter)
6666
case Patterns.LocalLazyInit(_) => unpickler.tryFind(method, localLazyInitCounter)
6767
case Patterns.LocalMethod(_) => unpickler.tryFind(method, localMethodCounter)
6868
case _ => unpickler.tryFind(method, methodCounter)
69-
localMethodCounter.printNotFound()
69+
anonFunCounter.printNotFound()
7070
methodCounter.printNotFound()
7171
localClassCounter.printReport()
7272
anonClassCounter.printReport()
@@ -81,8 +81,8 @@ class Scala3UnpicklerStats extends munit.FunSuite:
8181
checkCounter(anonClassCounter, 430)
8282
checkCounter(innerClassCounter, 2409)
8383
checkCounter(topLevelClassCounter, 1505)
84-
checkCounter(localMethodCounter, 2605, expectedAmbiguous = 2, expectedNotFound = 1)
85-
checkCounter(anonFunCounter, 6649, expectedAmbiguous = 331, expectedNotFound = 5)
84+
checkCounter(localMethodCounter, 2606, expectedAmbiguous = 2)
85+
checkCounter(anonFunCounter, 6651, expectedAmbiguous = 331, expectedNotFound = 3)
8686
checkCounter(adaptedAnonFunCounter, 288, expectedAmbiguous = 83)
8787
checkCounter(localLazyInitCounter, 108)
8888
checkCounter(methodCounter, 57744, expectedAmbiguous = 128)

0 commit comments

Comments
 (0)