Declaration "class MyParser[A] extends RegexParsers with PackratParsers" does not compile
oreshkor opened this issue · 1 comments
oreshkor commented
I wish to declare concrete class with a type parameter but scala compiler does not allow to do this if it extends both traits RegexParsers and PackratParsers simultaneously.
Compilation error says:
illegal trait super target found for method phrase required by trait PackratParsers;
[error] found : override def phrase: ([T](p: _1.Parser[T]): _1.Parser[T])( forSome { val _1: [A]MyParser[A] }) in trait RegexParsers;
[error] expected: def phrase: ([T](p: _1.Parser[T]): _1.Parser[T])( forSome { val _1: [A]MyParser[A] }) in trait Parsers
Is there any way how to bypass this?
SethTisue commented
REPL session demonstrating the issue:
scala> import scala.util.parsing.combinator._
import scala.util.parsing.combinator._
scala> class SimpleParser extends RegexParsers with PackratParsers
class SimpleParser
scala> class SimpleParser[A] extends RegexParsers with PackratParsers
^
error: illegal trait super target found for method phrase required by trait PackratParsers;
found : override def phrase: ([T](p: _1.Parser[T]): _1.Parser[T]) forSome { val _1: [A]SimpleParser[A] } in trait RegexParsers;
expected: def phrase: ([T](p: _1.Parser[T]): _1.Parser[T]) forSome { val _1: [A]SimpleParser[A] } in trait ParsersNote that Scala 3 actually accepts this code.
RegexParsers has:
override def phrase[T](p: Parser[T]): Parser[T] = ...
whereas PackratParsers has:
override def phrase[T](p: Parser[T]): PackratParser[T] = ...
I don't understand it would matter whether SimpleParser has a type parameter or not.