From 438bd01d53c6cb7417c7fa6cab86433a8f9b4fac Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 8 Nov 2023 15:51:59 +0100 Subject: [PATCH] Fix Scala 2 unpickler: do not load case accessor `val`s The class file contains both a case accessor `private val` and a case accessor `def`. We only need to load the `def` accessor. --- .github/workflows/ci.yaml | 2 +- .../dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 2 ++ compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala | 2 +- compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Synthesizer.scala | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5f5f616b76da..1f556a290fc3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -143,7 +143,7 @@ jobs: ./project/scripts/sbt ";sjsSandbox/run ;sjsSandbox/test ;sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test ;sjsCompilerTests/test" - name: Test with Scala 2 library TASTy - 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 + 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 test_windows_fast: runs-on: [self-hosted, Windows] diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index fe68d22f779a..8b939f5cc47e 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -450,6 +450,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas // Scala 2 sometimes pickle the same type parameter symbol multiple times // (see i11173 for an example), but we should only unpickle it once. || tag == TYPEsym && flags.is(TypeParam) && symScope(owner).lookup(name.asTypeName).exists + // We discard the private val representing a case accessor. We only load the case accessor def. + || flags.isAllOf(CaseAccessor| PrivateLocal, butNot = Method) then // skip this member return NoSymbol diff --git a/compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala b/compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala index 2dbfd9117f48..029616502c8c 100644 --- a/compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala +++ b/compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala @@ -329,7 +329,7 @@ class InlineReducer(inliner: Inliner)(using Context): val paramCls = paramType.classSymbol if (paramCls.is(Case) && unapp.symbol.is(Synthetic) && scrut <:< paramType) { val caseAccessors = - if (paramCls.is(Scala2x)) paramCls.caseAccessors.filter(_.is(Method)) + if paramCls.is(Scala2x) then paramCls.caseAccessors else paramCls.asClass.paramAccessors val selectors = for (accessor <- caseAccessors) diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index 8f5eec693609..05ef16961698 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -327,7 +327,7 @@ object PatternMatcher { /** Plan for matching the result of an unapply against argument patterns `args` */ def unapplyPlan(unapp: Tree, args: List[Tree]): Plan = { def caseClass = unapp.symbol.owner.linkedClass - lazy val caseAccessors = caseClass.caseAccessors.filter(_.is(Method)) + lazy val caseAccessors = caseClass.caseAccessors def isSyntheticScala2Unapply(sym: Symbol) = sym.isAllOf(SyntheticCase) && sym.owner.is(Scala2x) diff --git a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala index 6e1302c88398..ffb68a721fef 100644 --- a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala @@ -409,7 +409,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context): New(defn.RuntimeTupleMirrorTypeRef, Literal(Constant(arity)) :: Nil) def makeProductMirror(pre: Type, cls: Symbol, tps: Option[List[Type]]): TreeWithErrors = - val accessors = cls.caseAccessors.filterNot(_.isAllOf(PrivateLocal)) + val accessors = cls.caseAccessors val elemLabels = accessors.map(acc => ConstantType(Constant(acc.name.toString))) val typeElems = tps.getOrElse(accessors.map(mirroredType.resultType.memberInfo(_).widenExpr)) val nestedPairs = TypeOps.nestedPairs(typeElems)