Skip to content

Commit ede54b0

Browse files
committed
Improve hole tree checker
1 parent 86ff4f2 commit ede54b0

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -657,32 +657,37 @@ object TreeChecker {
657657

658658
// Check that we only add the captured type `T` instead of a more complex type like `List[T]`.
659659
// If we have `F[T]` with captured `F` and `T`, we should list `F` and `T` separately in the args.
660-
for arg <- (targs ::: args) do // TODO check targs and terms separately
661-
assert(arg.isTerm || arg.tpe.isInstanceOf[TypeRef], "Expected TypeRef in Hole type args but got: " + arg.tpe)
660+
for targ <- targs do
661+
assert(targ.isType)
662+
assert(targ.tpe.isInstanceOf[TypeRef], "Expected TypeRef in Hole targs but got: " + targ.tpe)
663+
for arg <- args do
664+
assert(arg.isTerm)
665+
assert(arg.isInstanceOf[RefTree], "Expected RefTree in Hole args but got: " + arg)
662666

663667
// Check result type of the hole
664668
if isTermHole then assert(tpt.typeOpt <:< pt)
665669
else assert(tpt.typeOpt =:= pt)
666670

667671
// Check that the types of the args conform to the types of the contents of the hole
668-
val argQuotedTypes = (targs ::: args).map { arg =>
669-
if arg.isTerm then
670-
val tpe = arg.typeOpt.widenTermRefExpr match
671-
case _: MethodicType =>
672-
// Special erasure for captured function references
673-
// See `SpliceTransformer.transformCapturedApplication`
674-
defn.AnyType
675-
case tpe => tpe
676-
defn.QuotedExprClass.typeRef.appliedTo(tpe)
677-
else defn.QuotedTypeClass.typeRef.appliedTo(arg.typeOpt)
672+
val targQuotedTypes = targs.map { arg =>
673+
defn.QuotedTypeClass.typeRef.appliedTo(arg.typeOpt)
674+
}
675+
val argQuotedTypes = args.map { arg =>
676+
val tpe = arg.typeOpt.widenTermRefExpr match
677+
case _: MethodicType =>
678+
// Special erasure for captured function references
679+
// See `SpliceTransformer.transformCapturedApplication`
680+
defn.AnyType
681+
case tpe => tpe
682+
defn.QuotedExprClass.typeRef.appliedTo(tpe)
678683
}
679684
val expectedResultType =
680685
if isTermHole then defn.QuotedExprClass.typeRef.appliedTo(tpt.typeOpt)
681686
else defn.QuotedTypeClass.typeRef.appliedTo(tpt.typeOpt)
682687
val contextualResult =
683688
defn.FunctionOf(List(defn.QuotesClass.typeRef), expectedResultType, isContextual = true)
684689
val expectedContentType =
685-
defn.FunctionOf(argQuotedTypes, contextualResult)
690+
defn.FunctionOf(targQuotedTypes ::: argQuotedTypes, contextualResult)
686691
assert(content.typeOpt =:= expectedContentType, i"expected content of the hole to be ${expectedContentType} but got ${content.typeOpt}")
687692

688693
tree1

0 commit comments

Comments
 (0)