Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2.13.9 regression which broke binary compatibility of case classes which are also value classes #10155

Merged
merged 1 commit into from Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,6 +24,7 @@ import symtab.Flags._
* def productArity: Int
* def productElement(n: Int): Any
* def productPrefix: String
* def productIterator: Iterator[Any] // required for binary compatibility of value classes
*
* Selectively added to case classes/objects, unless a non-default
* implementation already exists:
Expand Down Expand Up @@ -113,6 +114,10 @@ trait SyntheticMethods extends ast.TreeDSL {
(m0 ne meth) && !m0.isDeferred && !m0.isSynthetic && (m0.owner != AnyValClass) && (typeInClazz(m0) matches typeInClazz(meth))
}
}
def productIteratorMethod =
createMethod(nme.productIterator, iteratorOfType(AnyTpe))(_ =>
gen.mkMethodCall(ScalaRunTimeModule, nme.typedProductIterator, List(AnyTpe), List(mkThis))
)

def perElementMethod(name: Name, returnType: Type)(caseFn: Symbol => Tree): Tree =
createSwitchMethod(name, accessors.indices, returnType)(idx => caseFn(accessors(idx)))
Expand Down Expand Up @@ -259,6 +264,7 @@ trait SyntheticMethods extends ast.TreeDSL {
Product_productPrefix -> (() => constantNullary(nme.productPrefix, clazz.name.decode)),
Product_productArity -> (() => constantNullary(nme.productArity, arity)),
Product_productElement -> (() => perElementMethod(nme.productElement, AnyTpe)(mkThisSelect)),
Product_iterator -> (() => productIteratorMethod),
Product_canEqual -> (() => canEqualMethod)
)
}
Expand Down
1 change: 1 addition & 0 deletions test/files/run/idempotency-case-classes.check
Expand Up @@ -20,6 +20,7 @@ C(2,3)
case 1 => C.this.y
case _ => scala.runtime.Statics.ioobe[Any](x$1)
};
override <synthetic> def productIterator: Iterator[Any] = scala.runtime.ScalaRunTime.typedProductIterator[Any](C.this);
<synthetic> def canEqual(x$1: Any): Boolean = x$1.$isInstanceOf[C]();
override <synthetic> def productElementName(x$1: Int): String = x$1 match {
case 0 => "x"
Expand Down
1 change: 1 addition & 0 deletions test/files/scalap/caseClass.check
Expand Up @@ -6,6 +6,7 @@ case class CaseClass[A <: scala.Seq[scala.Int]](i: A, s: scala.Predef.String) ex
override def productPrefix: java.lang.String = { /* compiled code */ }
def productArity: scala.Int = { /* compiled code */ }
def productElement(x$1: scala.Int): scala.Any = { /* compiled code */ }
override def productIterator: scala.collection.Iterator[scala.Any] = { /* compiled code */ }
def canEqual(x$1: scala.Any): scala.Boolean = { /* compiled code */ }
override def productElementName(x$1: scala.Int): java.lang.String = { /* compiled code */ }
override def hashCode(): scala.Int = { /* compiled code */ }
Expand Down
1 change: 1 addition & 0 deletions test/files/scalap/caseObject.check
Expand Up @@ -3,6 +3,7 @@ case object CaseObject extends scala.AnyRef with scala.Product with scala.Serial
override def productPrefix: java.lang.String = { /* compiled code */ }
def productArity: scala.Int = { /* compiled code */ }
def productElement(x$1: scala.Int): scala.Any = { /* compiled code */ }
override def productIterator: scala.collection.Iterator[scala.Any] = { /* compiled code */ }
def canEqual(x$1: scala.Any): scala.Boolean = { /* compiled code */ }
override def hashCode(): scala.Int = { /* compiled code */ }
override def toString(): java.lang.String = { /* compiled code */ }
Expand Down
8 changes: 4 additions & 4 deletions test/scaladoc/run/implicits-chaining.scala
Expand Up @@ -23,15 +23,15 @@ object Test extends ScaladocModelTest {
val A = base._class("A")

conv = A._conversion(base.qualifiedName + ".convertToZ")
assertEquals(3, conv.members.length)
assertEquals(2, conv.members.length)
assertEquals(1, conv.constraints.length)

//// class B ///////////////////////////////////////////////////////////////////////////////////////////////////////////

val B = base._class("B")

conv = B._conversion(base.qualifiedName + ".convertToZ")
assertEquals(3, conv.members.length)
assertEquals(2, conv.members.length)
assertEquals(0, conv.constraints.length)

//// class C ///////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -45,15 +45,15 @@ object Test extends ScaladocModelTest {
val D = base._class("D")

conv = D._conversion(base.qualifiedName + ".convertToZ")
assertEquals(3, conv.members.length)
assertEquals(2, conv.members.length)
assertEquals(0, conv.constraints.length)

//// class E ///////////////////////////////////////////////////////////////////////////////////////////////////////////

val E = base._class("E")

conv = E._conversion(base.qualifiedName + ".convertToZ")
assertEquals(3, conv.members.length)
assertEquals(2, conv.members.length)
assertEquals(0, conv.constraints.length)

//// class F ///////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down