File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed
library/src-3.x/scala/internal/quoted Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,12 @@ object Matcher {
3737
3838 type Env = Set [(Symbol , Symbol )]
3939
40- inline def withEnv [T ](env : Env )(body : given Env => T ): T = body given env
40+ inline def withEnv [T ](env : Env )(body : => given Env => T ): T = body given env
41+
42+ /** Check that all trees match with =#= and concatenate the results with && */
43+ def (scrutinees : List [Tree ]) =##= (patterns : List [Tree ]) given Env : Matching =
44+ if (scrutinees.size != patterns.size) notMatched
45+ else foldMatchings(scrutinees.zip(patterns).map((s, p) => s =#= p): _* )
4146
4247 /** Check that the trees match and return the contents from the pattern holes.
4348 * Return None if the trees do not match otherwise return Some of a tuple containing all the contents in the holes.
@@ -69,10 +74,6 @@ object Matcher {
6974 def hasBindAnnotation (sym : Symbol ) =
7075 sym.annots.exists { case Apply (Select (New (TypeIdent (" patternBindHole" ))," <init>" ),List ()) => true ; case _ => true }
7176
72- def (scrutinees : List [Tree ]) =##= (patterns : List [Tree ]): Matching =
73- if (scrutinees.size != patterns.size) notMatched
74- else foldMatchings(scrutinees.zip(patterns).map((s, p) => s =#= p): _* )
75-
7677 /** Normalieze the tree */
7778 def normalize (tree : Tree ): Tree = tree match {
7879 case Block (Nil , expr) => normalize(expr)
Original file line number Diff line number Diff line change @@ -312,6 +312,18 @@ Pattern: {
312312}
313313Result: Some(List())
314314
315+ Scrutinee: {
316+ val a: scala.Int = 45
317+ val b: scala.Int = a
318+ ()
319+ }
320+ Pattern: {
321+ val x: scala.Int = 45
322+ val y: scala.Int = x
323+ ()
324+ }
325+ Result: Some(List())
326+
315327Scrutinee: {
316328 val a: scala.Int = 45
317329 a.+(a)
Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ object Test {
9191 matches({ val a : Int = 45 }, { var a : Int = 45 })
9292 matches({ val a : Int = 45 }, { @ patternBindHole var a : Int = patternHole })
9393 matches({ val a : Int = 45 ; a + a }, { val x : Int = 45 ; x + x })
94+ matches({ val a : Int = 45 ; val b = a }, { val x : Int = 45 ; val y = x })
9495 matches({ val a : Int = 45 ; a + a }, { val x : Int = 45 ; x + patternHole[Int ] })
9596 matches({ lazy val a : Int = 45 }, { val a : Int = 45 })
9697 matches({ lazy val a : Int = 45 }, { lazy val a : Int = 45 })
You can’t perform that action at this time.
0 commit comments