Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default values in case classes in Scala 3 #33

Closed
lolgab opened this issue Oct 17, 2022 · 0 comments · Fixed by #88
Closed

Support default values in case classes in Scala 3 #33

lolgab opened this issue Oct 17, 2022 · 0 comments · Fixed by #88
Milestone

Comments

@lolgab
Copy link
Member

lolgab commented Oct 17, 2022

Currently, default values in case classes are not handled correctly in Scala 3.
Example:

object Main {
  @mainargs.main
  case class Config(bar: String = "bar")

  def main(args: Array[String]): Unit = {
    val config = mainargs.ParserForClass[Config].constructOrExit(args)
    println(config)
  }
}

Scala 2 prints:

Missing argument: --bar <str>
Expected Signature: apply
  --bar <str>

Scala 2 prints:

Config(bar)
@lolgab lolgab changed the title Support default values in Scala 3 Support default values in case classes in Scala 3 Oct 17, 2022
lihaoyi added a commit that referenced this issue Aug 8, 2023
…n Scala3 (#88)

Fixes #33, as well as
`@arg` annotations not working on `case class` arguments (which doesn't
have an open issue)

Just need some special casing for `apply`/`<init>`, both for getting the
`apply` defaults (which are named `<init>$default$n` since they're
shared) and for getting the `apply` parameter annotations (which end up
on the `<init>` method parameters, rather than the `apply` method)

Re-enabled a bunch of previously-disabled tests, and added a new suite
to exercise default parameters in direct/nested scenarios
@lefou lefou added this to the 0.5.1 milestone Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants