Skip to content

Commit

Permalink
Merge pull request #10155 from som-snytt/issue/12650-missing-product-…
Browse files Browse the repository at this point in the history
…extension

Revert using mixin productIterator for case class
  • Loading branch information
lrytz committed Sep 26, 2022
2 parents 1d164ea + 1dc6e1b commit 8c6b49b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
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

0 comments on commit 8c6b49b

Please sign in to comment.