Skip to content

Add Scala 3 CanEqual for Parsers.~ to support strict equality - #646

Open
Philippus wants to merge 5 commits into
scala:mainfrom
Philippus:add-scala3-can-equal-for-a-tilde-b
Open

Philippus wants to merge 5 commits into
scala:mainfrom
Philippus:add-scala3-can-equal-for-a-tilde-b

Conversation

@Philippus

@Philippus Philippus commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

closes #477.

@Philippus
Philippus force-pushed the add-scala3-can-equal-for-a-tilde-b branch from 2648b51 to acb0a84 Compare August 14, 2026 20:49
@Philippus
Philippus force-pushed the add-scala3-can-equal-for-a-tilde-b branch from acb0a84 to 92dad84 Compare August 14, 2026 20:54
Comment thread build.sbt Outdated
@Philippus
Philippus requested review from SethTisue and lrytz September 6, 2026 20:53
Comment thread shared/src/main/scala-2.13+/scala/util/parsing/combinator/Parsers.scala Outdated
Comment thread build.sbt
class CanEqualsCompileTest extends RegexParsers {
val x: String ~ String = new~("a", "b")
val y: String ~ String = new~("a", "b")
x == y

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit to having been puzzled by #477, and this test isn't helping me understand it

477 says:

This would allow pattern-based productions to compile in the presence of strict equality

this doesn't sound like a description of what you've done here in the test...?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @klaeufer is around to add some clarification?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, was teaching last night...thanks for looking into this issue. Looks like my example evolved, and the URL I had included is no longer valid.

Without providing CanEqual[A ~ B, A ~ B], I couldn't get productions such as this to compile:

  def expr: Parser[Expr] =
    term ~! opt(("+" | "-") ~ term) ^^ {
      case l ~ None          => l
      case l ~ Some("+" ~ r) => Plus(l, r)
      case l ~ Some("-" ~ r) => Minus(l, r)
    }

The original source is here.

Let me know if there is anything else I should clarify.

Comment thread build.sbt Outdated
@Philippus
Philippus force-pushed the add-scala3-can-equal-for-a-tilde-b branch from 5f48a60 to 890dc4a Compare September 9, 2026 19:07
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

Successfully merging this pull request may close these issues.

Consider providing typesafe structural equality for A ~ B by default

3 participants