@@ -34,6 +34,10 @@ object Matcher {
3434 import reflection ._
3535 // TODO improve performance
3636
37+ /** Create a new matching with the resulting binding for the symbol */
38+ def bindingMatched (sym : Symbol ) =
39+ Some (Tuple1 (new Binding (sym.name, sym)))
40+
3741 /** Check that the trees match and return the contents from the pattern holes.
3842 * Return None if the trees do not match otherwise return Some of a tuple containing all the contents in the holes.
3943 *
@@ -52,9 +56,6 @@ object Matcher {
5256 sFlags.is(Lazy ) == pFlags.is(Lazy ) && sFlags.is(Mutable ) == pFlags.is(Mutable )
5357 }
5458
55- def bindingMatch (sym : Symbol ) =
56- Some (Tuple1 (new Binding (sym.name, sym)))
57-
5859 def hasBindingTypeAnnotation (tpt : TypeTree ): Boolean = tpt match {
5960 case Annotated (tpt2, Apply (Select (New (TypeIdent (" patternBindHole" )), " <init>" ), Nil )) => true
6061 case Annotated (tpt2, _) => hasBindingTypeAnnotation(tpt2)
@@ -148,7 +149,7 @@ object Matcher {
148149
149150 case (ValDef (_, tpt1, rhs1), ValDef (_, tpt2, rhs2)) if checkValFlags() =>
150151 val bindMatch =
151- if (hasBindingAnnotation(pattern.symbol) || hasBindingTypeAnnotation(tpt2)) bindingMatch (scrutinee.symbol)
152+ if (hasBindingAnnotation(pattern.symbol) || hasBindingTypeAnnotation(tpt2)) bindingMatched (scrutinee.symbol)
152153 else Some (())
153154 val returnTptMatch = treeMatches(tpt1, tpt2)
154155 val rhsEnv = env + (scrutinee.symbol -> pattern.symbol)
@@ -161,7 +162,7 @@ object Matcher {
161162 if (paramss1.size != paramss2.size) None
162163 else foldMatchings(paramss1.zip(paramss2).map { (params1, params2) => treesMatch(params1, params2) }: _* )
163164 val bindMatch =
164- if (hasBindingAnnotation(pattern.symbol)) bindingMatch (scrutinee.symbol)
165+ if (hasBindingAnnotation(pattern.symbol)) bindingMatched (scrutinee.symbol)
165166 else Some (())
166167 val tptMatch = treeMatches(tpt1, tpt2)
167168 val rhsEnv =
@@ -244,13 +245,24 @@ object Matcher {
244245 * `None` if it did not match or `Some(tup: Tuple)` if it matched where `tup` contains the contents of the holes.
245246 */
246247 def patternMatches (scrutinee : Pattern , pattern : Pattern )(implicit env : Set [(Symbol , Symbol )]): (Set [(Symbol , Symbol )], Option [Tuple ]) = (scrutinee, pattern) match {
247- case (Pattern .Value (v1), Pattern .Unapply (TypeApply (Select (patternHole @ Ident (" patternHole" ), " unapply" ), List (tpt)), Nil , Nil ))
248- if patternHole.symbol.owner.fullName == " scala.runtime.quoted.Matcher$" =>
249- (env, Some (Tuple1 (v1.seal)))
248+ // case (Pattern.Value(v1), Pattern.Unapply(TypeApply(Select(patternHole @ Ident("patternHole"), "unapply"), List(tpt)), Nil, Nil))
249+ // if patternHole.symbol.owner.fullName == "scala.runtime.quoted.Matcher$" =>
250+ // (env, Some(Tuple1(v1.seal)))
251+
252+ case (Pattern .Bind (name1, pat1), Pattern .Unapply (Select (Ident (" patternMatchBindHole" ), " unapply" ), Nil , List (Pattern .Bind (name2, pat2))))
253+ // TODO if pattern.symbol == ... =>
254+ =>
255+ val (env1, patMatch) = patternMatches(pat1, pat2)
256+ (env1, foldMatchings(bindingMatched(scrutinee.symbol), patMatch))
257+
258+ case (Pattern .Value (Ident (" _" )), Pattern .Value (Ident (" _" ))) => // TODO add Wildcard to patterns
259+ val bindEnv = env + (scrutinee.symbol -> pattern.symbol)
260+ (bindEnv, Some (()))
250261
251262 case (Pattern .Value (v1), Pattern .Value (v2)) =>
252263 (env, treeMatches(v1, v2))
253264
265+
254266 case (Pattern .Bind (name1, body1), Pattern .Bind (name2, body2)) =>
255267 val bindEnv = env + (scrutinee.symbol -> pattern.symbol)
256268 patternMatches(body1, body2)(bindEnv)
0 commit comments