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

Declaration "class MyParser[A] extends RegexParsers with PackratParsers" does not compile #398

Open
oreshkor opened this issue Jun 10, 2021 · 1 comment

Comments

@oreshkor
Copy link

oreshkor commented Jun 10, 2021

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
Copy link
Member

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 Parsers

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants