Skip to content

Commit c363aff

Browse files
committed
Add typedAppliedSpliceWithTypes
1 parent 7531d60 commit c363aff

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,32 @@ trait QuotesAndSplices {
167167
typedSplicePattern(untpd.cpy.SplicePattern(tree)(splice.body, Nil, args), pt)
168168
}
169169

170+
/** Types a splice applied to some type arguments and arguments
171+
* `$f[targs1, ..., targsn](arg1, ..., argn)` in a quote pattern.
172+
*
173+
* TODO-18217: Remove follwing notes on complete
174+
* Refer to: typedTypeApply
175+
*/
176+
def typedAppliedSpliceWithTypes(tree: untpd.Apply, pt: Type)(using Context): Tree = {
177+
assert(ctx.mode.is(Mode.QuotedPattern))
178+
val untpd.Apply(typeApplyTree @ untpd.TypeApply(splice: untpd.SplicePattern, typeargs), args) = tree: @unchecked
179+
def isInBraces: Boolean = splice.span.end != splice.body.span.end
180+
if isInBraces then // ${x}[...](...) match an application
181+
// TODO-18127: typedTypeApply cares about named arguments. Do we want to care as well?
182+
val typedTypeargs = typeargs.map(arg => typedType(arg))
183+
// TODO-18217: Why do we use typedExpr here?
184+
val typedArgs = args.map(arg => typedExpr(arg))
185+
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
186+
val splice1 = typedSplicePattern(splice, ProtoTypes.PolyProto(typedArgs, defn.FunctionOf(argTypes, pt)))
187+
val typedTypeApply = untpd.cpy.TypeApply(typeApplyTree)(splice1.select(nme.apply), typedTypeargs)
188+
untpd.cpy.Apply(tree)(typedTypeApply, typedArgs).withType(pt)
189+
else // $x(...) higher-order quasipattern
190+
// TODO-18271: Case for highr-order quasi-quote pattern with type params
191+
if typeargs.isEmpty || args.isEmpty then
192+
report.error("Missing arguments for open pattern", tree.srcPos)
193+
typedSplicePattern(untpd.cpy.SplicePattern(tree)(splice.body, typeargs, args), pt)
194+
}
195+
170196
/** Type check a type binding reference in a quoted pattern.
171197
*
172198
* If no binding exists with that name, this becomes the definition of a new type binding.

0 commit comments

Comments
 (0)