Skip to content

Contravariance in first Rule type param not always honored #172

@sirthias

Description

@sirthias

There is a bug in (the application of) the TailSwitch logic, which causes certain parsers to compile when they shouldn't:

class Par extends Parser {
  def A: Rule1[Any] = ???
  def B: PopRule[Int :: HNil] = ???
  def C = rule { A ~ B }
}

The problem appears only when the 2nd rule consumes all of the 1st rule's output.
This parser for example correctly doesn't compile:

class Par extends Parser {
  def A: Rule2[String, Any] = ???
  def B: PopRule[Int :: HNil] = ???
  def C: Rule1[String] = rule { A ~ B }
}

I think the reason for this issue is that we currently use two TailSwitch type logic application for computing the output of the ~ operator, whereby no distinction is made between the application for a contravariant type parameter (the first) and the application for a covariant type parameter (the second).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions