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.

constructor default parameters are reused for case class apply

See original GitHub issue

A 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:open
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bishaboshacommented, Jun 8, 2022

perhaps an extra note in the documentation about the dropping of generation of default parameter forwarders for synthetic apply methods is required

1reaction
oderskycommented, Aug 18, 2021

Great! @bishabosha Can I leave the issue here for to you to close once the scala/scala side is resolved?

Read more comments on GitHub >

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

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