Use predictions instead of post-hoc conversions when dealing with :
and =>
#15251
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.
This PR does some cleanups in the parser base that should make it easier to implement the changed
fewerBraces rules where the lambda is now preceded by
:
.The problem is that this creates two ambiguities:
With self types:
can be alternatively read as a function application of
self
to a lambda. The first commit solves thisby defaulting to a self type if the code appears at the start of a template. In the long run, this would not
be a problem since we want to move away from self types and replace them by a
This
type declaration.But for now we need to fix the ambiguity.
With the way formal parameters of lambdas are parsed. Consider the expression:
Here, we used to parse
(x: Int => Int)
as an expression (i.e. an ascription with aTyped
node) and then converted this to a parameterValDef
when the second=>
was encountered. Because of this hack, wehad to allow function types like
Int => Int
in type ascriptions inside parentheses, but not elsewhere, even though this relaxation is not backed by the official Scala syntax. WithfewerBraces
the first expression inside(...)
would be parsed as an application of the formx(y => z)
, which would complicate things further.The second commit solves this by lookahead scanning when a
:
ascription inside parentheses is encountered. If the closing parenthesis is followed by=>
or?=>
we classify the prefix as a list of bindings and parse appropriately. No need to convert type ascriptions to parameters.The third commit enforces the official Scala grammar, requiring(...)
around function types in ascriptions. It is enabled from source version 3.2.Fixes #15260