File tree Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 684
684
tests (mapv #(mapv (fn [t] (analyze expr-env t)) %) tests)
685
685
thens (mapv #(analyze env %) thens)
686
686
default (analyze env default )]
687
- (assert (every? (fn [t] (and (= :constant (:op t))
688
- ((some-fn number? string? char?) (:form t))))
687
+ (assert (every? (fn [t]
688
+ (or
689
+ (-> t :info :const )
690
+ (and (= :constant (:op t))
691
+ ((some-fn number? string? char?) (:form t)))))
689
692
(apply concat tests))
690
- " case* tests must be numbers or strings " )
693
+ " case* tests must be numbers, strings, or constants " )
691
694
{:env env :op :case* :form form
692
695
:v v :tests tests :thens thens :default default
693
696
:children (vec (concat [v] tests thens (if default [default ])))}))
783
786
:var (symbol (str ns-name) (str sym))}))
784
787
(when (namespace sym)
785
788
(throw (error env " Can't def ns-qualified name" )))
789
+ (when (:const (resolve-var (dissoc env :locals ) sym))
790
+ (throw (error env " Can't redefine a constant" )))
786
791
(when-let [doc (:doc args)]
787
792
(when-not (string? doc)
788
793
(throw (error env " Too many arguments to def" ))))
1178
1183
1179
1184
(symbol? target)
1180
1185
(do
1186
+ (when (:const (resolve-var (dissoc env :locals ) target))
1187
+ (throw (error env " Can't set! a constant" )))
1181
1188
(let [local (-> env :locals target)]
1182
1189
(when-not (or (nil? local)
1183
1190
(and (:field local)
Original file line number Diff line number Diff line change 1481
1481
(assoc-test m test expr env)))
1482
1482
{} (partition 2 clauses))
1483
1483
esym (gensym )
1484
+ const? #(:const (and (list? %) (ana/resolve-var env (last %))))
1484
1485
tests (keys pairs)]
1485
1486
(cond
1486
- (every? (some-fn core/number? core/string? core/char?) tests)
1487
+ (every? (some-fn core/number? core/string? core/char? const? ) tests)
1487
1488
(core/let [no-default (if (odd? (count clauses)) (butlast clauses) clauses)
1488
1489
tests (mapv #(if (seq? %) (vec %) [%]) (take-nth 2 no-default))
1489
1490
thens (vec (take-nth 2 (drop 1 no-default)))]
Original file line number Diff line number Diff line change 328
328
(deftest test-cljs-1105
329
329
; ; munge turns - into _, must preserve the dash first
330
330
(is (not= (a/gen-constant-id :test-kw )
331
- (a/gen-constant-id :test_kw ))))
331
+ (a/gen-constant-id :test_kw ))))
332
+ ; ; Constants
333
+
334
+ (deftest test-constants
335
+ (is (.startsWith
336
+ (try
337
+ (a/analyze test-env '(do (def ^:const foo 123 ) (def foo 246 )))
338
+ (catch Exception e
339
+ (.getMessage e)))
340
+ " Can't redefine a constant" ))
341
+ (is (.startsWith
342
+ (try
343
+ (a/analyze test-env '(do (def ^:const foo 123 ) (set! foo 246 )))
344
+ (catch Exception e
345
+ (.getMessage e)))
346
+ " Can't set! a constant" )))
You can’t perform that action at this time.
0 commit comments