Permalink
Browse files

* src/main/clojure/clojure/core/match.clj: MATCH-34: remove infix or …

…pattern, now must use :or prefix
  • Loading branch information...
swannodette committed Oct 28, 2011
1 parent 18174b7 commit 0195f7211d44e15d40a35445b4882fcaf5bc9fb6
Showing with 27 additions and 24 deletions.
  1. +10 −3 src/main/clojure/clojure/core/match.clj
  2. +17 −21 src/test/clojure/clojure/core/match/test/core/error_msg.clj
@@ -1456,9 +1456,16 @@
(recur pats (conj seen pat) dups))
(vector? pat) (recur (concat pats pat) seen dups)
(map? pat) (recur (concat pats (vals pat)) seen dups)
- (seq? pat) (case (second pat)
- :as (recur (concat pats (take-nth 2 pat)) seen dups)
- (recur (conj pats (first pat)) seen dups))
+ (seq? pat) (cond
+ (= (first pat) :or) (let [wds (map wildcards-and-duplicates
+ (map list (take-nth 2 pat)))
+ mseen (apply set/union (map first wds))]
+ (recur pats (set/union seen mseen)
+ (apply set/union dups
+ (set/intersection seen mseen)
+ (map second wds))))
+ (= (second pat) :as) (recur (concat pats (take-nth 2 pat)) seen dups)
+ :else (recur (conj pats (first pat)) seen dups))
:else (recur pats seen dups)))
[seen dups])))
@@ -55,14 +55,12 @@
[1] :a1
[1]))))
-(comment
- (deftest match-list-syntax-error
- (is (thrown-with-msg?
- AssertionError
- #"Invalid list syntax :what in \(1 :what a\). Valid syntax: \[:vector | :as :when\]"
- (m-to-clj [x]
- [(1 :what a)] :a1))))
- )
+(deftest match-list-syntax-error
+ (is (thrown-with-msg?
+ AssertionError
+ #"^Invalid list syntax :what in \(1 :what a\)"
+ (m-to-clj [x]
+ [(1 :what a)] :a1))))
(deftest match-else-clause-error
(is (thrown-with-msg?
@@ -97,16 +95,14 @@
[a a] a
:else 1))))
-(comment
- (deftest match-duplicate-wildcards2
- (is (thrown-with-msg?
- AssertionError
- #"Pattern row 1: Pattern row reuses wildcards in \[.*\]. The following wildcards are ambiguous: aa, x. There's no guarantee that the matched values will be same. Rename the occurrences uniquely."
- (m-to-clj [xx yy]
- [x (:or [:black [:red [:red a x b] y c] z d]
- [:black [:red a x [:red b y c]] z d]
- [:black a x [:red [:red b y c] z d]]
- [:black aa x [:red [:black aa y c] z d]]
- [:black a x [:red b y [:red c z d]]]) ] a
- :else 1))))
- )
+(deftest match-duplicate-wildcards2
+ (is (thrown-with-msg?
+ AssertionError
+ #"Pattern row 1: Pattern row reuses wildcards in \[.*\]. The following wildcards are ambiguous: aa, x. There's no guarantee that the matched values will be same. Rename the occurrences uniquely."
+ (m-to-clj [xx yy]
+ [x (:or [:black [:red [:red a x b] y c] z d]
+ [:black [:red a x [:red b y c]] z d]
+ [:black a x [:red [:red b y c] z d]]
+ [:black aa x [:red [:black aa y c] z d]]
+ [:black a x [:red b y [:red c z d]]])] a
+ :else 1))))

0 comments on commit 0195f72

Please sign in to comment.