Skip to content

Commit ee17211

Browse files
committed
Tree check QuotePattern and SplicePattern
1 parent 962466a commit ee17211

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,25 @@ object TreeChecker {
699699
assert(!tree.expr.isInstanceOf[untpd.Quote] || inInlineMethod, i"missed quote cancellation in $tree")
700700
super.typedSplice(tree, pt)
701701

702+
override def typedQuotePattern(tree: untpd.QuotePattern, pt: Type)(using Context): Tree =
703+
assert(ctx.mode.is(Mode.Pattern))
704+
for binding <- tree.bindings do
705+
assert(binding.isInstanceOf[untpd.Bind], i"expected Bind in QuotePattern bindings but was: $binding")
706+
super.typedQuotePattern(tree, pt)
707+
708+
override def typedSplicePattern(tree: untpd.SplicePattern, pt: Type)(using Context): Tree =
709+
assert(ctx.mode.is(Mode.QuotedPattern))
710+
def isAppliedIdent(rhs: untpd.Tree): Boolean = rhs match
711+
case _: Ident => true
712+
case rhs: GenericApply => isAppliedIdent(rhs.fun)
713+
case _ => false
714+
def isEtaExpandedIdent(arg: untpd.Tree): Boolean = arg match
715+
case closureDef(ddef) => isAppliedIdent(ddef.rhs)
716+
case _ => false
717+
for arg <- tree.args do
718+
assert(arg.isInstanceOf[untpd.Ident] || isEtaExpandedIdent(arg), i"expected Ident SplicePattern args but was: $arg")
719+
super.typedSplicePattern(tree, pt)
720+
702721
override def typedHole(tree: untpd.Hole, pt: Type)(using Context): Tree = {
703722
val tree1 @ Hole(isTerm, idx, args, content) = super.typedHole(tree, pt): @unchecked
704723

0 commit comments

Comments
 (0)