Skip to content

Commit 315823f

Browse files
committed
Improve hole tree checker
1 parent 1ad1804 commit 315823f

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
@@ -662,32 +662,37 @@ object TreeChecker {
662662

663663
// Check that we only add the captured type `T` instead of a more complex type like `List[T]`.
664664
// If we have `F[T]` with captured `F` and `T`, we should list `F` and `T` separately in the args.
665-
for arg <- (targs ::: args) do // TODO check targs and terms separately
666-
assert(arg.isTerm || arg.tpe.isInstanceOf[TypeRef], "Expected TypeRef in Hole type args but got: " + arg.tpe)
665+
for targ <- targs do
666+
assert(targ.isType)
667+
assert(targ.tpe.isInstanceOf[TypeRef], "Expected TypeRef in Hole targs but got: " + targ.tpe)
668+
for arg <- args do
669+
assert(arg.isTerm)
670+
assert(arg.isInstanceOf[RefTree], "Expected RefTree in Hole args but got: " + arg)
667671

668672
// Check result type of the hole
669673
if isTermHole then assert(tpt.typeOpt <:< pt)
670674
else assert(tpt.typeOpt =:= pt)
671675

672676
// Check that the types of the args conform to the types of the contents of the hole
673-
val argQuotedTypes = (targs ::: args).map { arg =>
674-
if arg.isTerm then
675-
val tpe = arg.typeOpt.widenTermRefExpr match
676-
case _: MethodicType =>
677-
// Special erasure for captured function references
678-
// See `SpliceTransformer.transformCapturedApplication`
679-
defn.AnyType
680-
case tpe => tpe
681-
defn.QuotedExprClass.typeRef.appliedTo(tpe)
682-
else defn.QuotedTypeClass.typeRef.appliedTo(arg.typeOpt.widenTermRefExpr)
677+
val targQuotedTypes = targs.map { arg =>
678+
defn.QuotedTypeClass.typeRef.appliedTo(arg.typeOpt.widenTermRefExpr)
679+
}
680+
val argQuotedTypes = args.map { arg =>
681+
val tpe = arg.typeOpt.widenTermRefExpr match
682+
case _: MethodicType =>
683+
// Special erasure for captured function references
684+
// See `SpliceTransformer.transformCapturedApplication`
685+
defn.AnyType
686+
case tpe => tpe
687+
defn.QuotedExprClass.typeRef.appliedTo(tpe)
683688
}
684689
val expectedResultType =
685690
if isTermHole then defn.QuotedExprClass.typeRef.appliedTo(tpt.typeOpt)
686691
else defn.QuotedTypeClass.typeRef.appliedTo(tpt.typeOpt)
687692
val contextualResult =
688693
defn.FunctionOf(List(defn.QuotesClass.typeRef), expectedResultType, isContextual = true)
689694
val expectedContentType =
690-
defn.FunctionOf(argQuotedTypes, contextualResult)
695+
defn.FunctionOf(targQuotedTypes ::: argQuotedTypes, contextualResult)
691696
assert(content.typeOpt =:= expectedContentType, i"unexpected content of hole\nexpected: ${expectedContentType}\nwas: ${content.typeOpt}")
692697

693698
tree1

0 commit comments

Comments
 (0)