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

Make Parser covariant in Scala 3 #453

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package caseapp.core.parser

private[parser] object Internal {
type uncheckedVarianceScala2 = scala.annotation.unchecked.uncheckedVariance
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package caseapp.core.parser

private[parser] object Internal {
final class uncheckedVarianceScala2 extends scala.annotation.StaticAnnotation
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.language.implicitConversions
* @tparam T:
* success result type
*/
abstract class Parser[T] extends ParserMethods[T] {
abstract class Parser[+T] extends ParserMethods[T] {

import Parser.Step

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package caseapp.core.complete
import caseapp.core.Arg
import caseapp.core.help.{WithFullHelp, WithHelp}

trait Completer[T] { self =>
trait Completer[-T] { self =>
def optionName(prefix: String, state: Option[T]): List[CompletionItem]
def optionValue(arg: Arg, prefix: String, state: Option[T]): List[CompletionItem]
def argument(prefix: String, state: Option[T]): List[CompletionItem]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import caseapp.core.Error
import caseapp.{ExtraName, Group, HelpMessage, Recurse}
import caseapp.core.parser.Parser

final case class WithFullHelp[T](
final case class WithFullHelp[+T](
@Recurse
withHelp: WithHelp[T],
@Group("Help")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import caseapp.core.Error
* @tparam T:
* type to which usage and help options are added
*/
final case class WithHelp[T](
final case class WithHelp[+T](
@Group("Help")
@HelpMessage("Print usage and exit")
usage: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import caseapp.core.util.Formatter
import caseapp.Name
import caseapp.core.complete.Completer
import caseapp.core.complete.CompletionItem

import scala.annotation.tailrec

trait ParserMethods[T] { parser: Parser[T] =>
trait ParserMethods[+T] { parser: Parser[T @Internal.uncheckedVarianceScala2] =>

import Parser.Step

Expand Down