constructor default parameters are reused for case class apply
See original GitHub issueA case class apply method does not have default parameters generated, instead the constructor default parameters are reused, I believe that this is undocumented - causing https://github.com/scala/bug/issues/12409
Compiler version
3.0.1
Minimized code
case class CaseClassDefault(value: Int = 1)
val foo = Scala3CaseClass.apply()
Output
val foo: CaseClassDefault = CaseClassDefault.apply(CaseClassDefault.`<init>$default$1`)
Expectation
val foo: CaseClassDefault = CaseClassDefault.apply(CaseClassDefault.`apply$default$1`)
Notes
extract from generated code:
final lazy module val CaseClassDefault: CaseClassDefault$ =
new CaseClassDefault$()
final module class CaseClassDefault$() extends AnyRef() {
this: CaseClassDefault.type =>
def apply(value: Int): CaseClassDefault = new CaseClassDefault(value)
def unapply(x$1: CaseClassDefault): CaseClassDefault = x$1
override def toString: String = "CaseClassDefault"
def $lessinit$greater$default$1: Int @uncheckedVariance = 1
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Case-classes and its default constructors - Stack Overflow
The question is - why compiler allows such writings? In Java, defining constructor with any parameters, makes the default constructor not ...
Read more >Case classes with default parameters that depend on other ...
I am fascinated by the concept of case classes. ... However, let's assume another constructor that automatically sets the value of email:
Read more >Python Class Constructors: Control Your Object Instantiation
In this tutorial, you'll learn how class constructors work in Python. ... one of the most popular techniques is to use optional arguments....
Read more >about Classes - PowerShell | Microsoft Learn
Constructor. Constructors enable you to set default values and validate object logic at the moment of creating the instance of the class.
Read more >Effective Dart: Usage
DON'T use an explicit default value of null . ... Note that this guideline doesn't apply to the named constructors for those classes....
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 Free
Top 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
perhaps an extra note in the documentation about the dropping of generation of default parameter forwarders for synthetic apply methods is required
Great! @bishabosha Can I leave the issue here for to you to close once the scala/scala side is resolved?