Skip to content

Commit c5842db

Browse files
committed
Reinterpret ::.next$access$1 when unpickling from Scala 2
1 parent 8cb4945 commit c5842db

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,14 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
454454
// skip this member
455455
return NoSymbol
456456

457+
// Remove case accessor `next$access$1` and make `next` the case accessor
458+
// TODO generalize to all Scala 2 accessors with this form
459+
if owner == defn.ConsClass then
460+
if name == nme.next then
461+
flags = flags | Synthetic | CaseAccessor
462+
else if name == "next$access$1".toTermName then
463+
return NoSymbol
464+
457465
name = name.adjustIfModuleClass(flags)
458466
if (flags.is(Method))
459467
name =

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ class DottyBytecodeTests extends DottyBytecodeTest {
10581058
TypeOp(CHECKCAST, "scala/collection/immutable/$colon$colon"),
10591059
VarOp(ASTORE, 3),
10601060
VarOp(ALOAD, 3),
1061-
Invoke(INVOKEVIRTUAL, "scala/collection/immutable/$colon$colon", "next$access$1", "()Lscala/collection/immutable/List;", false),
1061+
Invoke(INVOKEVIRTUAL, "scala/collection/immutable/$colon$colon", "next", "()Lscala/collection/immutable/List;", false),
10621062
VarOp(ASTORE, 4),
10631063
VarOp(ALOAD, 3),
10641064
Invoke(INVOKEVIRTUAL, "scala/collection/immutable/$colon$colon", "head", "()Ljava/lang/Object;", false),
@@ -1112,7 +1112,7 @@ class DottyBytecodeTests extends DottyBytecodeTest {
11121112
Invoke(INVOKESTATIC, "scala/runtime/BoxesRunTime", "unboxToInt", "(Ljava/lang/Object;)I", false),
11131113
VarOp(ISTORE, 4),
11141114
VarOp(ALOAD, 3),
1115-
Invoke(INVOKEVIRTUAL, "scala/collection/immutable/$colon$colon", "next$access$1", "()Lscala/collection/immutable/List;", false),
1115+
Invoke(INVOKEVIRTUAL, "scala/collection/immutable/$colon$colon", "next", "()Lscala/collection/immutable/List;", false),
11161116
VarOp(ASTORE, 5),
11171117
Op(ICONST_1),
11181118
VarOp(ILOAD, 4),

tests/neg/i18884.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test(xs: ::[Int]): List[Int] =
2+
xs.next$access$1 // error

tests/run/typeclass-derivation3.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ Cons(hd = Cons(hd = 11, tl = Cons(hd = 22, tl = Cons(hd = 33, tl = Nil))), tl =
99
Cons(hd = Left(x = 1), tl = Cons(hd = Right(x = Pair(x = 2, y = 3)), tl = Nil))
1010
Cons(hd = Left(x = 1), tl = Cons(hd = Right(x = Pair(x = 2, y = 3)), tl = Nil))
1111
true
12-
::(head = 1, next$access$1 = ::(head = 2, next$access$1 = ::(head = 3, next$access$1 = Nil())))
13-
::(head = ::(head = 1, next$access$1 = Nil()), next$access$1 = ::(head = ::(head = 2, next$access$1 = ::(head = 3, next$access$1 = Nil())), next$access$1 = Nil()))
14-
::(head = Nil(), next$access$1 = ::(head = ::(head = 1, next$access$1 = Nil()), next$access$1 = ::(head = ::(head = 2, next$access$1 = ::(head = 3, next$access$1 = Nil())), next$access$1 = Nil())))
12+
::(head = 1, next = ::(head = 2, next = ::(head = 3, next = Nil())))
13+
::(head = ::(head = 1, next = Nil()), next = ::(head = ::(head = 2, next = ::(head = 3, next = Nil())), next = Nil()))
14+
::(head = Nil(), next = ::(head = ::(head = 1, next = Nil()), next = ::(head = ::(head = 2, next = ::(head = 3, next = Nil())), next = Nil())))

0 commit comments

Comments
 (0)