-
Notifications
You must be signed in to change notification settings - Fork 131
PackratParsers#phrase: explicit return type (fixes #369) #370
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nice find, @SethTisue is this something that may be of interest to the scala 3 team?
Philippus
Philippus
approved these changes
Apr 11, 2021
the Scala 2 behavior is usually considered undesirable here, and I believe the Scala 3 behavior is intentional: scala/bug#7212
I've opened a ticket suggesting the Scala 3 migration guide mention this: scalacenter/scala-3-migration-guide#181
thank you Ilya!
Scala 3.0.0-RC3 is around the corner, so we'll publish the fix then.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
This fixes #369.
TL;DR A missed result type for
PackratParsers#phrase
results in a different behaviour (Scala 2.x. vs Scala 3.x) for edgy cases.Long explanation:
It seems (I was not able to quickly find a corresponding reference) that in Scala 3.0 if an overriding method doesn't explicitly specify the result type, the result type of the base method is taken (even if the compiler can figure out a more concrete type).
This leads to a corner case with PackratParsers#phrase, which in 2.x has the effective/inferred type
def phrase[T](p: Parser[T]): PackratParser[T]
and in 3.x has the effective/inferred typedef phrase[T](p: Parser[T]): Parser[T]
.This results into an extra implicit conversion
parser2packrat
being inserted even if the current parser is already a Packrat Parser. This, in turn, breaks assumptions of thememo
method.Providing explicit return type fixes #369 subtlety.
The added test is OK for Scala 2.x, but fails for Scala 3.x - as can be seen from this run - https://github.com/ilya-klyuchnikov/scala-parser-combinators/commit/92a338ea19567614d30b1f6f1b8b7953849779a5.
Correspondingly, after the fix, the test is OK for both Scala 2.x and Scala 3.x
I have been bitten by this subtlety - while migrating https://github.com/ilya-klyuchnikov/tapl-scala to Scala 3.