@@ -19,7 +19,7 @@ private[quoted] object Matcher {
1919
2020 inline private def withEnv [T ](env : Env )(body : => given Env => T ): T = body given env
2121
22- class SymBinding (val sym : Symbol )
22+ class SymBinding (val sym : Symbol , val fromAbove : Boolean )
2323
2424 def termMatch (scrutineeTerm : Term , patternTerm : Term , hasTypeSplices : Boolean ): Option [Tuple ] = {
2525 implicit val env : Env = Set .empty
@@ -30,7 +30,7 @@ private[quoted] object Matcher {
3030 // that we have found and seal them in a quoted.Type
3131 matchings.asOptionOfTuple.map { tup =>
3232 Tuple .fromArray(tup.toArray.map { // TODO improve performace
33- case x : SymBinding => internal.Context_GADT_approximation (the[Context ])(x.sym, true ).seal
33+ case x : SymBinding => internal.Context_GADT_approximation (the[Context ])(x.sym, ! x.fromAbove ).seal
3434 case x => x
3535 })
3636 }
@@ -50,7 +50,7 @@ private[quoted] object Matcher {
5050 // that we have found and seal them in a quoted.Type
5151 matchings.asOptionOfTuple.map { tup =>
5252 Tuple .fromArray(tup.toArray.map { // TODO improve performace
53- case x : SymBinding => internal.Context_GADT_approximation (the[Context ])(x.sym, true ).seal
53+ case x : SymBinding => internal.Context_GADT_approximation (the[Context ])(x.sym, ! x.fromAbove ).seal
5454 case x => x
5555 })
5656 }
@@ -67,11 +67,18 @@ private[quoted] object Matcher {
6767
6868 private def hasBindAnnotation (sym : Symbol ) = sym.annots.exists(isBindAnnotation)
6969
70+ private def hasFromAboveAnnotation (sym : Symbol ) = sym.annots.exists(isFromAboveAnnotation)
71+
7072 private def isBindAnnotation (tree : Tree ): Boolean = tree match {
7173 case New (tpt) => tpt.symbol == internal.Definitions_InternalQuoted_patternBindHoleAnnot
7274 case annot => annot.symbol.owner == internal.Definitions_InternalQuoted_patternBindHoleAnnot
7375 }
7476
77+ private def isFromAboveAnnotation (tree : Tree ): Boolean = tree match {
78+ case New (tpt) => tpt.symbol == internal.Definitions_InternalQuoted_formAboveAnnot
79+ case annot => annot.symbol.owner == internal.Definitions_InternalQuoted_formAboveAnnot
80+ }
81+
7582 /** Check that all trees match with `mtch` and concatenate the results with && */
7683 private def matchLists [T ](l1 : List [T ], l2 : List [T ])(mtch : (T , T ) => Matching ): Matching = (l1, l2) match {
7784 case (x :: xs, y :: ys) => mtch(x, y) && matchLists(xs, ys)(mtch)
@@ -160,7 +167,7 @@ private[quoted] object Matcher {
160167
161168 case (Block (stats1, expr1), Block (binding :: stats2, expr2)) if isTypeBinding(binding) =>
162169 qctx.tasty.internal.Context_GADT_addToConstraint (the[Context ])(binding.symbol :: Nil )
163- matched(new SymBinding (binding.symbol)) && Block (stats1, expr1) =#= Block (stats2, expr2)
170+ matched(new SymBinding (binding.symbol, hasFromAboveAnnotation(binding.symbol) )) && Block (stats1, expr1) =#= Block (stats2, expr2)
164171
165172 case (Block (stat1 :: stats1, expr1), Block (stat2 :: stats2, expr2)) =>
166173 withEnv(the[Env ] + (stat1.symbol -> stat2.symbol)) {
@@ -170,7 +177,7 @@ private[quoted] object Matcher {
170177 case (scrutinee, Block (typeBindings, expr2)) if typeBindings.forall(isTypeBinding) =>
171178 val bindingSymbols = typeBindings.map(_.symbol)
172179 qctx.tasty.internal.Context_GADT_addToConstraint (the[Context ])(bindingSymbols)
173- bindingSymbols.foldRight(scrutinee =#= expr2)((x, acc) => matched(new SymBinding (x)) && acc)
180+ bindingSymbols.foldRight(scrutinee =#= expr2)((x, acc) => matched(new SymBinding (x, hasFromAboveAnnotation(x) )) && acc)
174181
175182 case (If (cond1, thenp1, elsep1), If (cond2, thenp2, elsep2)) =>
176183 cond1 =#= cond2 && thenp1 =#= thenp2 && elsep1 =#= elsep2
0 commit comments