Skip to content

Commit b66354d

Browse files
committed
Add QuotedRuntimePatterns_higherOrderHoleWithTypes
This commit also allows splitQuotePattern to support type args
1 parent b01b407 commit b66354d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ class Definitions {
882882
@tu lazy val QuotedRuntimePatterns: Symbol = requiredModule("scala.quoted.runtime.Patterns")
883883
@tu lazy val QuotedRuntimePatterns_patternHole: Symbol = QuotedRuntimePatterns.requiredMethod("patternHole")
884884
@tu lazy val QuotedRuntimePatterns_higherOrderHole: Symbol = QuotedRuntimePatterns.requiredMethod("higherOrderHole")
885+
@tu lazy val QuotedRuntimePatterns_higherOrderHoleWithTypes: Symbol = QuotedRuntimePatterns.requiredMethod("higherOrderHoleWithTypes")
885886
@tu lazy val QuotedRuntimePatterns_patternTypeAnnot: ClassSymbol = QuotedRuntimePatterns.requiredClass("patternType")
886887
@tu lazy val QuotedRuntimePatterns_fromAboveAnnot: ClassSymbol = QuotedRuntimePatterns.requiredClass("fromAbove")
887888

compiler/src/dotty/tools/dotc/quoted/QuotePatterns.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,16 @@ object QuotePatterns:
205205
val patType1 = patType.translateFromRepeated(toArray = false)
206206
val pat1 = if (patType eq patType1) pat else pat.withType(patType1)
207207
patBuf += pat1
208-
if args.isEmpty then ref(defn.QuotedRuntimePatterns_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span)
209-
else ref(defn.QuotedRuntimePatterns_higherOrderHole.termRef).appliedToType(tree.tpe).appliedTo(SeqLiteral(args, TypeTree(defn.AnyType))).withSpan(tree.span)
208+
if typeargs.isEmpty && args.isEmpty then ref(defn.QuotedRuntimePatterns_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span)
209+
else if typeargs.isEmpty then
210+
ref(defn.QuotedRuntimePatterns_higherOrderHole.termRef)
211+
.appliedToType(tree.tpe)
212+
.appliedTo(SeqLiteral(args, TypeTree(defn.AnyType)))
213+
.withSpan(tree.span)
214+
else ref(defn.QuotedRuntimePatterns_higherOrderHoleWithTypes.termRef)
215+
.appliedToTypeTrees(List(TypeTree(tree.tpe), tpd.hkNestedPairsTypeTree(typeargs)))
216+
.appliedTo(SeqLiteral(args, TypeTree(defn.AnyType)))
217+
.withSpan(tree.span)
210218
case _ =>
211219
super.transform(tree)
212220
}

library/src/scala/quoted/runtime/Patterns.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package scala.quoted.runtime
22

33
import scala.annotation.{Annotation, compileTimeOnly}
4+
import scala.annotation.experimental
45

56
@compileTimeOnly("Illegal reference to `scala.quoted.runtime.Patterns`")
67
object Patterns {
@@ -26,6 +27,14 @@ object Patterns {
2627
@compileTimeOnly("Illegal reference to `scala.quoted.runtime.Patterns.higherOrderHole`")
2728
def higherOrderHole[U](args: Any*): U = ???
2829

30+
/** A higher order splice in a quoted pattern is desugared by the compiler into a call to this method.
31+
*
32+
* Calling this method in source has undefined behavior at compile-time
33+
*/
34+
@experimental
35+
@compileTimeOnly("Illegal reference to `scala.quoted.runtime.Patterns.higherOrderHole`")
36+
def higherOrderHoleWithTypes[U, T](args: Any*): U = ???
37+
2938
/** A splice of a name in a quoted pattern is that marks the definition of a type splice.
3039
*
3140
* Adding this annotation in source has undefined behavior at compile-time

0 commit comments

Comments
 (0)