Skip to content

Commit

Permalink
Reinterpret ::.next$access$1 when unpickling from Scala 2
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 13, 2023
1 parent 8cb4945 commit c5842db
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,14 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
// skip this member
return NoSymbol

// Remove case accessor `next$access$1` and make `next` the case accessor
// TODO generalize to all Scala 2 accessors with this form
if owner == defn.ConsClass then
if name == nme.next then
flags = flags | Synthetic | CaseAccessor
else if name == "next$access$1".toTermName then
return NoSymbol

name = name.adjustIfModuleClass(flags)
if (flags.is(Method))
name =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ class DottyBytecodeTests extends DottyBytecodeTest {
TypeOp(CHECKCAST, "scala/collection/immutable/$colon$colon"),
VarOp(ASTORE, 3),
VarOp(ALOAD, 3),
Invoke(INVOKEVIRTUAL, "scala/collection/immutable/$colon$colon", "next$access$1", "()Lscala/collection/immutable/List;", false),
Invoke(INVOKEVIRTUAL, "scala/collection/immutable/$colon$colon", "next", "()Lscala/collection/immutable/List;", false),
VarOp(ASTORE, 4),
VarOp(ALOAD, 3),
Invoke(INVOKEVIRTUAL, "scala/collection/immutable/$colon$colon", "head", "()Ljava/lang/Object;", false),
Expand Down Expand Up @@ -1112,7 +1112,7 @@ class DottyBytecodeTests extends DottyBytecodeTest {
Invoke(INVOKESTATIC, "scala/runtime/BoxesRunTime", "unboxToInt", "(Ljava/lang/Object;)I", false),
VarOp(ISTORE, 4),
VarOp(ALOAD, 3),
Invoke(INVOKEVIRTUAL, "scala/collection/immutable/$colon$colon", "next$access$1", "()Lscala/collection/immutable/List;", false),
Invoke(INVOKEVIRTUAL, "scala/collection/immutable/$colon$colon", "next", "()Lscala/collection/immutable/List;", false),
VarOp(ASTORE, 5),
Op(ICONST_1),
VarOp(ILOAD, 4),
Expand Down
2 changes: 2 additions & 0 deletions tests/neg/i18884.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test(xs: ::[Int]): List[Int] =
xs.next$access$1 // error
6 changes: 3 additions & 3 deletions tests/run/typeclass-derivation3.check
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Cons(hd = Cons(hd = 11, tl = Cons(hd = 22, tl = Cons(hd = 33, tl = Nil))), tl =
Cons(hd = Left(x = 1), tl = Cons(hd = Right(x = Pair(x = 2, y = 3)), tl = Nil))
Cons(hd = Left(x = 1), tl = Cons(hd = Right(x = Pair(x = 2, y = 3)), tl = Nil))
true
::(head = 1, next$access$1 = ::(head = 2, next$access$1 = ::(head = 3, next$access$1 = Nil())))
::(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()))
::(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())))
::(head = 1, next = ::(head = 2, next = ::(head = 3, next = Nil())))
::(head = ::(head = 1, next = Nil()), next = ::(head = ::(head = 2, next = ::(head = 3, next = Nil())), next = Nil()))
::(head = Nil(), next = ::(head = ::(head = 1, next = Nil()), next = ::(head = ::(head = 2, next = ::(head = 3, next = Nil())), next = Nil())))

0 comments on commit c5842db

Please sign in to comment.