Skip to content

Commit

Permalink
Add type argument encoding to SPLICEPATTERN
Browse files Browse the repository at this point in the history
Future proof for scala#18271.
  • Loading branch information
nicolasstucki committed Apr 22, 2024
1 parent 31fe897 commit 743cc0b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,14 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
bindings.foreach(pickleTree)
}
case SplicePattern(pat, args) =>
val targs = Nil // SplicePattern `targs` will be added with #18271
writeByte(SPLICEPATTERN)
withLength {
pickleTree(pat)
pickleType(tree.tpe)
for targ <- targs do
writeByte(EXPLICITtpt)
pickleTree(targ)
args.foreach(pickleTree)
}
case Hole(_, idx, args, _) =>
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,8 @@ class TreeUnpickler(reader: TastyReader,
case SPLICEPATTERN =>
val pat = readTree()
val patType = readType()
val args = until(end)(readTree())
val (targs, args) = until(end)(readTree()).span(_.isType)
assert(targs.isEmpty, "unexpected type arguments in SPLICEPATTERN") // `targs` will be needed for #18271. Until this fearure is added they should be empty.
SplicePattern(pat, args, patType)
case HOLE =>
readHole(end, isTerm = true)
Expand Down
2 changes: 1 addition & 1 deletion tasty/src/dotty/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Standard-Section: "ASTs" TopLevelStat*
SELECTouter Length levels_Nat qual_Term underlying_Type -- Follow `levels` outer links, starting from `qual`, with given `underlying` type
QUOTE Length body_Term bodyTpe_Type -- Quoted expression `'{ body }` of a body typed as `bodyTpe`
SPLICE Length expr_Term tpe_Type -- Spliced expression `${ expr }` typed as `tpe`
SPLICEPATTEN Length pat_Term tpe_Type args_Term* -- Pattern splice `${pat}` or `$pat(args*)` in a quoted pattern of type `tpe`
SPLICEPATTEN Length pat_Term tpe_Type targs_Type* args_Term* -- Pattern splice `${pat}` or `$pat[targs*](args*)` in a quoted pattern of type `tpe`.
-- patterns:
BIND Length boundName_NameRef patType_Type pat_Term -- name @ pat, wherev `patType` is the type of the bound symbol
ALTERNATIVE Length alt_Term* -- alt1 | ... | altn as a pattern
Expand Down

0 comments on commit 743cc0b

Please sign in to comment.