Skip to content

possible bug in documentation with @derives[Parser, Help] #653

@kuba86

Description

@kuba86

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."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions