@@ -61,15 +61,23 @@ object QuotePatterns:
61
61
}
62
62
}.apply(Set .empty, quotePattern.body)
63
63
64
- // TODO-18271: Refactor this
64
+ /*
65
+ * This part checks well-formedness of arguments to hoas patterns.
66
+ * (1) Type arguments of a hoas patterns must be introduced in the quote pattern.ctxShow
67
+ * Examples
68
+ * well-formed: '{ [A] => (x : A) => $a[A](x) } // A is introduced in the quote pattern
69
+ * ill-formed: '{ (x : Int) => $a[Int](x) } // Int is defined outside of the quote pattern
70
+ * (2) If value arguments of a hoas pattern has a type with type variables that are introduced in
71
+ * the quote pattern, those type variables should be in type arguments to the hoas patternHole
72
+ * Examples
73
+ * well-formed: '{ [A] => (x : A) => $a[A](x) } // a : [A] => (x:A) => A
74
+ * ill-formed: '{ [A] => (x : A) => $a(x) } // a : (x:A) => A ...but A is undefined; hence ill-formed
75
+ */
65
76
new tpd.TreeTraverser {
66
77
override def traverse (tree : tpd.Tree )(using Context ): Unit = tree match {
67
78
case tree : SplicePattern =>
68
79
def uncapturedTypeVars (arg : tpd.Tree , capturedTypeVars : List [tpd.Tree ]) =
69
80
val capturedTypeVarsSet = capturedTypeVars.map(_.symbol).toSet
70
- println(" --- uncapturedTypeVars" )
71
- println(s " typevars = ${typevars.map(_.show)}" )
72
- println(s " capturedTypevars = ${capturedTypeVarsSet.map(_.show)}" )
73
81
new TypeAccumulator [Set [Type ]] {
74
82
def apply (x : Set [Type ], tp : Type ): Set [Type ] =
75
83
if typevars.contains(tp.typeSymbol) && ! capturedTypeVarsSet.contains(tp.typeSymbol) then
@@ -78,13 +86,11 @@ object QuotePatterns:
78
86
foldOver(x, tp)
79
87
}.apply(Set .empty, arg.tpe)
80
88
81
- // Type arguments to a splice patterns must be type variables that are introduced
82
- // inside the quote pattern
83
- for (typearg <- tree.typeargs)
89
+ for (typearg <- tree.typeargs) // case (1)
84
90
do
85
91
if ! typevars.contains(typearg.symbol) then
86
92
report.error(" Type arguments of a hoas pattern needs to be introduced in the quoted pattern" , typearg.srcPos)
87
- for (arg <- tree.args)
93
+ for (arg <- tree.args) // case (2)
88
94
do
89
95
if ! uncapturedTypeVars(arg, tree.typeargs).isEmpty then
90
96
report.error(" Type variables that this argument depends on are not captured in this hoas pattern" , arg.srcPos)
0 commit comments