From 743cc0b0f79a5886267ef6da2d5b101b6e98c54e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 22 Apr 2024 09:39:38 +0200 Subject: [PATCH] Add type argument encoding to SPLICEPATTERN Future proof for #18271. --- compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala | 4 ++++ compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 3 ++- tasty/src/dotty/tools/tasty/TastyFormat.scala | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index 55d25eeb3654..f8a0f725ea52 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -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, _) => diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index ee3c98632b95..64ea2d497295 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -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) diff --git a/tasty/src/dotty/tools/tasty/TastyFormat.scala b/tasty/src/dotty/tools/tasty/TastyFormat.scala index 413702ea0d71..164243d3b469 100644 --- a/tasty/src/dotty/tools/tasty/TastyFormat.scala +++ b/tasty/src/dotty/tools/tasty/TastyFormat.scala @@ -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