@@ -17,6 +17,7 @@ import dotty.tools.dotc.core.Types._
1717import dotty .tools .dotc .reporting ._
1818import dotty .tools .dotc .typer .Implicits ._
1919import dotty .tools .dotc .typer .Inferencing ._
20+ import dotty .tools .dotc .typer .ProtoTypes ._
2021import dotty .tools .dotc .util .Spans ._
2122import dotty .tools .dotc .util .Stats .record
2223
@@ -108,6 +109,26 @@ trait QuotesAndSplices {
108109 }
109110 }
110111
112+ /** Types a splice applied to some arguments `$f(arg1, ..., argn)` in a quote pattern.
113+ *
114+ * The tree is desugared into `$f.apply(arg1, ..., argn)` where the expression `$f`
115+ * is expected to type as a function type `(T1, ..., Tn) => R`.
116+ * `Ti` is the type of the argument `argi` and R if the type of the prototype.
117+ * The prototype must be fully defined to be able to infer the type of `R`.
118+ */
119+ def typedAppliedSplice (tree : untpd.Apply , pt : Type )(using Context ): Tree = {
120+ assert(ctx.mode.is(Mode .QuotedPattern ))
121+ val untpd .Apply (splice : untpd.Splice , args) = tree
122+ if (isFullyDefined(pt, ForceDegree .flipBottom)) then
123+ val typedArgs = args.map(arg => typedExpr(arg))
124+ val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
125+ val splice1 = typedSplice(splice, defn.FunctionOf (argTypes, pt))
126+ Apply (splice1.select(nme.apply), typedArgs).withType(pt).withSpan(tree.span)
127+ else
128+ ctx.error(i " Type must be fully defined. " , splice.sourcePos)
129+ tree.withType(UnspecifiedErrorType )
130+ }
131+
111132 /** Translate ${ t: Type[T] }` into type `t.splice` while tracking the quotation level in the context */
112133 def typedTypSplice (tree : untpd.TypSplice , pt : Type )(using Context ): Tree = {
113134 record(" typedTypSplice" )
0 commit comments