Case class allows case-field named "productArity", which creates havoc with Product
See original GitHub issue% scala -version Scala code runner version 3.1.1 – Copyright 2002-2022, LAMP/EPFL
Case class allows case-field with name productArity without any warning/error. This silently breaks functionality of Product. It is not obvious that case class extends Product and field with productArity should not be used. Suggestion: make productArity illegal as a case-field or at least warning.
Example:
object Bug {
case class Problem(productArity : Int)
def main(args : Array[String]) : Unit = {
val cc = Problem(42)
println("wtf?: "+cc.productArity) //42
}
}
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Case Classes | Scala Book
This lesson provides an introduction to 'case classes' in Scala. ... An apply method is created in the companion object of the class,...
Read more >Scala case class extending Product with Serializable
This is an expected behavior because of how case class works. case class automatically extends two traits, namely Product and Serializable .
Read more >Scala Topics - Case Classes - Catch the Dot
In this blog post, I am going to cover Scala's Case class ... into Case classes, lets spend sometime looking into Scala's Product...
Read more >Scala case classes in depth - Alessandro Lacava
Creates a class and its companion object. Implements the apply method that you can use as a factory. This lets you create instances...
Read more >add: productElementName to case classes #2948 - scala/bug
We can call productArity to find how many items on a Product/case class, can call productElement(i) to find the value of i -...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same behavior in Scala 2.
Possible messaging:
productArity, productElement, and productElementName should be overridden together
. Orconsider also overriding productElement
, etc.Is it a coincidence that
jraty
is nearly an anagram ofarity
?Due to an early experiment, Scala 2
Product#productIterator
was still calling intoScalaRunTime.typedProductIterator
[sic].Scala 3 did not inherit that behavior, but does emit
_1
component members. That is commented out in Scala 2.Someone recently asked about
fromProduct
in Scala 3.Maybe this ticket can be an umbrella ticket for doc. I guess on Scala 3 it is
DOT Product
.There is similar friction around case companions, such as access modifiers for synthetics or whether it extends
Function
.