question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
som-snyttcommented, Apr 12, 2022

Same behavior in Scala 2.

Possible messaging: productArity, productElement, and productElementName should be overridden together. Or consider also overriding productElement, etc.

Is it a coincidence that jraty is nearly an anagram of arity?

0reactions
som-snyttcommented, Apr 13, 2022

Due to an early experiment, Scala 2 Product#productIterator was still calling into ScalaRunTime.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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found