Skip to content

Commit

Permalink
Make Parser covariant in Scala 3 (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault authored Jan 26, 2023
1 parent 5ca4fd9 commit d892207
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 5 deletions.
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

0 comments on commit d892207

Please sign in to comment.