New Syntax for Capture Variables and Explicit Capture Polymorphism #22758
+464
−141
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.
[skip community_build]
Closes #22490
Builds on #22725
This aim of this PR is reducing the clunkyness of the explicit capture polymorphism syntax following internal discussions.
[cap B, A <: {B,x,y,z} ]
.Morally, capture variables are both terms and types (analogy: companion objects).
We might still in the future support uninterrupted curried lists of explicit capture-set parameters.
^
symbol for capture variables.cap C <: x
is the same ascap C <: {x}
.cap
members and parameters cannot be higher-kinded, i.e., they take no type-level parameters.cap
members and parameters may have context bounds, like ordinary type parameters.cap
parameter lists in higher-kinded types.using
for context parameters, we permit applying explicit capture sets withcap
(assumefoo
's signature from above):are currently not planned, but may be supported in the futureand named capture arguments coincidentally "just work":Standard type inference applies to other type parameters (such as
T
andX
offoo
).Extended syntax of capture set bounds (maybe, not planned now).
def foo3[cap A, B, C <: A & B] = ???
def foo4[cap A, B, C <: A | B]
, since we can always use the set notation{A,B}
.Rebase on Separation checking for product types #22539 and patch all tests.
Document the parser changes for capture checking in the internal
syntax.md
.Add specialized syntax error messages for cap lists & co.
Remove the old
[C^]
syntax for good.Make cap members and lists pretty-printed (with option to turn off).
Let parser mark capture variables with some attachment to be used by later phases.