@@ -27,10 +27,11 @@ object Matcher {
27
27
*
28
28
* @param scrutineeExpr `Expr[_]` on which we are pattern matching
29
29
* @param patternExpr `Expr[_]` containing the pattern tree
30
+ * @param hasTypeSplices `Boolean` notify if the pattern has type splices (if so we use a GADT context)
30
31
* @param reflection instance of the reflection API (implicitly provided by the macro)
31
32
* @return None if it did not match, `Some(tup)` if it matched where `tup` contains `Expr[Ti]``
32
33
*/
33
- def unapply [TypeBindings <: Tuple , Tup <: Tuple ](scrutineeExpr : Expr [_])(implicit patternExpr : Expr [_], reflection : Reflection ): Option [Tup ] = {
34
+ def unapply [TypeBindings <: Tuple , Tup <: Tuple ](scrutineeExpr : Expr [_])(implicit patternExpr : Expr [_], hasTypeSplices : Boolean , reflection : Reflection ): Option [Tup ] = {
34
35
// TODO improve performance
35
36
import reflection .{Bind => BindPattern , _ }
36
37
import Matching ._
@@ -335,18 +336,24 @@ object Matcher {
335
336
336
337
implied for Env = Set .empty
337
338
338
- {
339
- // TODO only set GADT context when needed
340
- implicit val ctx2 = reflection.kernel.Context_GADT_setFreshGADTBounds (rootContext)
341
- val matchings = scrutineeExpr.unseal.underlyingArgument =#= patternExpr.unseal.underlyingArgument
342
- val res = matchings.asOptionOfTuple.map { tup =>
343
- Tuple .fromArray(tup.toArray.map { // TODO improve code
344
- case x : SymBinding => reflection.kernel.Context_GADT_approximation (ctx2)(x.sym, true ).seal
345
- case x => x
346
- })
339
+ val res = {
340
+ if (hasTypeSplices) {
341
+ implied for Context = reflection.kernel.Context_GADT_setFreshGADTBounds (rootContext)
342
+ val matchings = scrutineeExpr.unseal.underlyingArgument =#= patternExpr.unseal.underlyingArgument
343
+ // After matching and doing all subtype check, we have to aproximate all the type bindings
344
+ // that we have found and seal them in a quoted.Type
345
+ matchings.asOptionOfTuple.map { tup =>
346
+ Tuple .fromArray(tup.toArray.map { // TODO improve performace
347
+ case x : SymBinding => kernel.Context_GADT_approximation (the[Context ])(x.sym, true ).seal
348
+ case x => x
349
+ })
350
+ }
351
+ }
352
+ else {
353
+ scrutineeExpr.unseal.underlyingArgument =#= patternExpr.unseal.underlyingArgument
347
354
}
348
- res.asInstanceOf [Option [Tup ]]
349
355
}
356
+ res.asInstanceOf [Option [Tup ]]
350
357
}
351
358
352
359
/** Result of matching a part of an expression */
0 commit comments