-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add quoted pattern type splices #6504
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
Add quoted pattern type splices #6504
Conversation
caec229 to
ccd2222
Compare
a5374ae to
d9fd1f0
Compare
50c6137 to
02ee27f
Compare
|
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM
| val patType = defn.tupleType(splices.tpes.map(_.widen)) | ||
| val splicePat = typed(untpd.Tuple(splices.map(untpd.TypedSplice(_))).withSpan(quoted.span), patType) | ||
|
|
||
| val (typeBindings, shape, splices) = splitQuotePattern(quoted1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a description of the scheme for translating patterns to doc comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
| ref(defn.InternalQuoted_patternHoleR).appliedToType(splice.tpe).withSpan(splice.span) | ||
| } | ||
|
|
||
| /** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a description of the scheme for translating patterns to doc comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
723df7f to
486d552
Compare
|
Rebased |
145f33b to
bf29a51
Compare
|
Will need to be rebased |
fc4b9e8 to
c2fd6e5
Compare
|
@odersky Requested changes have been addressed. |
c2fd6e5 to
732033f
Compare
|
Rebased |
Support type spliced in quoted patterns
New quoted patterns
We introduce type splices
$tin type positions. In the following example we want to match a list of any element typeIf
lsis matched against aList[Int]the typetwill beType[Int]or if it was aList[Foo]it would return aType[Foo].Note that in
$t,tis a pattern and therefore is just a name binding. A fresh type is generated for it and cannot be named.We can also splice on a type definition
type $t. Unlike the previous variant the type will be named$tand can be used by referencing it using back-ticks and could be bounded.Overview of desugaring and tying
For each type splice we will create a new type binding in the pattern match (
$t @ _in this case) and a corresponding type in the quoted pattern as a hole (@patternBindHole type $tin this case). All these generated types are inserted at the start of the quoted code.For type definition we do the same as above, except that we just reuse
type $tas our@patternBindHole type $t.