Skip to content

Commit 8c58cbf

Browse files
committed
Inline _N case class product members under -Yscala2-stdlib
Scala 2 does not generate the methods `_N`. This is solved by inlining those calls, which removes the calls to those methods and the definitions of those methods in the bytecode.
1 parent 1d1f0d7 commit 8c58cbf

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,10 @@ object desugar {
637637
// new C[...](p1, ..., pN)(moreParams)
638638
val (caseClassMeths, enumScaffolding) = {
639639
def syntheticProperty(name: TermName, tpt: Tree, rhs: Tree) =
640-
DefDef(name, Nil, tpt, rhs).withMods(synthetic)
640+
val mods =
641+
if ctx.settings.Yscala2Stdlib.value then synthetic | Inline
642+
else synthetic
643+
DefDef(name, Nil, tpt, rhs).withMods(mods)
641644

642645
def productElemMeths =
643646
val caseParams = derivedVparamss.head.toArray

project/MiMaFilters.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,6 @@ object MiMaFilters {
185185
// Companion module class: Missing type java.io.Serializable
186186
ProblemFilters.exclude[MissingTypesProblem]("scala.*$"),
187187

188-
// Case class product accessors
189-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.*._1"),
190-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.*._2"),
191-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.*._3"),
192-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.*._4"),
193-
194188
// abstract method elemTag()scala.reflect.ClassTag in class scala.collection.mutable.ArraySeq does not have a correspondent in other version
195189
ProblemFilters.exclude[DirectAbstractMethodProblem]("scala.collection.immutable.ArraySeq.elemTag"),
196190
ProblemFilters.exclude[DirectAbstractMethodProblem]("scala.collection.mutable.ArraySeq.elemTag"),

stdlib-bootstrapped/test/Main.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ object HelloWorld:
1515

1616
testScala2UnapplySignatures()
1717
testScala2ObjectParents()
18+
testScala2ProductMembers()
1819
}
1920

2021
def testScala2UnapplySignatures() = {
@@ -31,3 +32,11 @@ object HelloWorld:
3132
assert(!typeChecks("Either: scala.deriving.Mirror.Sum"))
3233
assert(!typeChecks("Either: scala.deriving.Mirror"))
3334
}
35+
def testScala2ProductMembers() = {
36+
Some(1)._1
37+
Right(1)._1
38+
(1, 2)._1
39+
(1, 2)._2
40+
::(1, Nil)._1
41+
::(1, Nil)._2
42+
}

0 commit comments

Comments
 (0)