-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
Looking at the documentation https://alexarchambault.github.io/case-app/define/ there is a suggestion "When defining a case class for options, it is recommended to derive case-app type classes for it in its companion object, like"
case class Options(
foo: Int
)
// Scala 2
object Options {
implicit lazy val parser: Parser[Options] = Parser.derive
implicit lazy val help: Help[Options] = Help.derive
}
// Scala 3
@derives[Parser, Help]
object Options
When running the following example:
//> using scala "3"
//> using dependency "com.github.alexarchambault::case-app:2.1.0"
import caseapp.*
case class Options(
foo: Int
)
@derives[Parser, Help]
object Options
object MyApp extends CaseApp[Options] {
def run(options: Options, remaining: RemainingArgs): Unit = {
println(options)
}
}
there will be a compilation error:
scala-cli run . -- run --foo=7
Compiling project (Scala 3.8.1, JVM (21))
[error] ./caseapp.scala:10:2
[error] Not found: type derives
[error] @derives[Parser, Help]
[error] ^^^^^^^
Error compiling project (Scala 3.8.1, JVM (21))
Compilation failed
by removing
@derives[Parser, Help]
object Options
the code compiles correctly.
What would be a proper way to use @derives in CaseApp with Scala 3 to meet the goal for "we highly recommend deriving them there, in order to make incremental compilation faster when the file defining the options isn't modified."
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels