Skip to content

Commit 2961661

Browse files
committed
Reinterpret ::.next$access$1 when unpickling from Scala 2
1 parent 6d59d65 commit 2961661

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
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
@@ -462,6 +462,14 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
462462
flags &~= Method | Accessor
463463
if !flags.is(StableRealizable) then flags |= Mutable
464464

465+
// Remove case accessor `next$access$1` and make `next` the case accessor
466+
// TODO generalize to all Scala 2 accessors with this form
467+
if owner == defn.ConsClass then
468+
if name == nme.next then
469+
flags = flags | CaseAccessor
470+
else if name == "next$access$1".toTermName then
471+
return NoSymbol
472+
465473
name = name.adjustIfModuleClass(flags)
466474
if (flags.is(Method))
467475
name =

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)