Skip to content

Commit 683af6c

Browse files
committed
Fix Scala 2 unpickler: do not load case accessor vals
The class file contains both a case accessor `private val` and a case accessor `def`. We only need to load the `def` accessor.
1 parent 3430cbb commit 683af6c

File tree

5 files changed

+6
-4
lines changed

5 files changed

+6
-4
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ jobs:
143143
./project/scripts/sbt ";sjsSandbox/run ;sjsSandbox/test ;sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test ;sjsCompilerTests/test"
144144
145145
- name: Test with Scala 2 library TASTy
146-
run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryTasty := true ;scala3-bootstrapped/testCompilation i5" # only test a subset of test to avoid doubling the CI execution time
146+
run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryTasty := true ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala" # only test a subset of test to avoid doubling the CI execution time
147147

148148
test_windows_fast:
149149
runs-on: [self-hosted, Windows]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
450450
// Scala 2 sometimes pickle the same type parameter symbol multiple times
451451
// (see i11173 for an example), but we should only unpickle it once.
452452
|| tag == TYPEsym && flags.is(TypeParam) && symScope(owner).lookup(name.asTypeName).exists
453+
// We discard the private val representing a case accessor. We only load the case accessor def.
454+
|| flags.isAllOf(CaseAccessor| Private, butNot = Method)
453455
then
454456
// skip this member
455457
return NoSymbol

compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class InlineReducer(inliner: Inliner)(using Context):
329329
val paramCls = paramType.classSymbol
330330
if (paramCls.is(Case) && unapp.symbol.is(Synthetic) && scrut <:< paramType) {
331331
val caseAccessors =
332-
if (paramCls.is(Scala2x)) paramCls.caseAccessors.filter(_.is(Method))
332+
if paramCls.is(Scala2x) then paramCls.caseAccessors
333333
else paramCls.asClass.paramAccessors
334334
val selectors =
335335
for (accessor <- caseAccessors)

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ object PatternMatcher {
327327
/** Plan for matching the result of an unapply against argument patterns `args` */
328328
def unapplyPlan(unapp: Tree, args: List[Tree]): Plan = {
329329
def caseClass = unapp.symbol.owner.linkedClass
330-
lazy val caseAccessors = caseClass.caseAccessors.filter(_.is(Method))
330+
lazy val caseAccessors = caseClass.caseAccessors
331331

332332
def isSyntheticScala2Unapply(sym: Symbol) =
333333
sym.isAllOf(SyntheticCase) && sym.owner.is(Scala2x)

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
409409
New(defn.RuntimeTupleMirrorTypeRef, Literal(Constant(arity)) :: Nil)
410410

411411
def makeProductMirror(pre: Type, cls: Symbol, tps: Option[List[Type]]): TreeWithErrors =
412-
val accessors = cls.caseAccessors.filterNot(_.isAllOf(PrivateLocal))
412+
val accessors = cls.caseAccessors
413413
val elemLabels = accessors.map(acc => ConstantType(Constant(acc.name.toString)))
414414
val typeElems = tps.getOrElse(accessors.map(mirroredType.resultType.memberInfo(_).widenExpr))
415415
val nestedPairs = TypeOps.nestedPairs(typeElems)

0 commit comments

Comments
 (0)