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 {
37
37
38
38
type Env = Set [(Symbol , Symbol )]
39
39
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): _* )
41
46
42
47
/** Check that the trees match and return the contents from the pattern holes.
43
48
* 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 {
69
74
def hasBindAnnotation (sym : Symbol ) =
70
75
sym.annots.exists { case Apply (Select (New (TypeIdent (" patternBindHole" ))," <init>" ),List ()) => true ; case _ => true }
71
76
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
-
76
77
/** Normalieze the tree */
77
78
def normalize (tree : Tree ): Tree = tree match {
78
79
case Block (Nil , expr) => normalize(expr)
Original file line number Diff line number Diff line change @@ -312,6 +312,18 @@ Pattern: {
312
312
}
313
313
Result: Some(List())
314
314
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
+
315
327
Scrutinee: {
316
328
val a: scala.Int = 45
317
329
a.+(a)
Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ object Test {
91
91
matches({ val a : Int = 45 }, { var a : Int = 45 })
92
92
matches({ val a : Int = 45 }, { @ patternBindHole var a : Int = patternHole })
93
93
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 })
94
95
matches({ val a : Int = 45 ; a + a }, { val x : Int = 45 ; x + patternHole[Int ] })
95
96
matches({ lazy val a : Int = 45 }, { val a : Int = 45 })
96
97
matches({ lazy val a : Int = 45 }, { lazy val a : Int = 45 })
You can’t perform that action at this time.
0 commit comments