Permalink
Browse files

MATCH-66: Cannot match entire/single value

Given a simple pattern like the following:

(match 3 x x)

Bad match code would be generated. The issue was that 3 is an
expression and needs an occurence (a local). However the match
provided by the user here is just a wildcard line. Wildcard line cases
were not checking to see if there are are any expressions in the
occurrences - they just emitted a leaf node, we now check for
expression occurences and emit a wrapping bind node if necessary.
  • Loading branch information...
1 parent ede2646 commit 02a833efb959e0518f264ded3b98ce4215b5622c @swannodette swannodette committed May 18, 2013
Showing with 13 additions and 2 deletions.
  1. +5 −2 src/main/clojure/clojure/core/match.clj
  2. +8 −0 src/test/clojure/clojure/core/match/test/core.clj
View
7 src/main/clojure/clojure/core/match.clj
@@ -772,8 +772,11 @@
bs (row-bindings f ocrs)
_ (trace-dag
(str "First row all wildcards, add leaf-node. action: " a
- " bindings: " (into [] bs)))]
- (leaf-node a bs)))
+ " bindings: " (into [] bs)))
+ node (leaf-node a bs)]
+ (if (some expression? ocrs)
+ (bind-node (bind-variables ocrs) node)
+ node)))
(defn first-column-chosen-case
"Case 3a: The first column is chosen. Compute and return a switch/bind node
View
8 src/test/clojure/clojure/core/match/test/core.clj
@@ -715,3 +715,11 @@
[:c] :a2
:else :a3))
:a2)))
+
+
+;; =============================================================================
+;; Tickets
+
+(deftest match-66
+ (is (= (match 3 x x) 3))
+ (is (= (match 'my-sym a a) 'my-sym)))

0 comments on commit 02a833e

Please sign in to comment.