Skip to content

Commit 7be4ae0

Browse files
swannodetteRolT
andauthored
CLJS-3371: Invalid warning on record constructor (#168)
Record constructor has a second arity that accept 2 additionnal parameters Co-authored-by: Roland THIOLLIERE <[email protected]>
1 parent 8b3ce24 commit 7be4ae0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,10 @@
25542554
known-num-fields (:num-fields ctor-var)
25552555
argc (count args)]
25562556
(when (and (not (-> ctor meta :internal-ctor))
2557-
(some? known-num-fields) (not= known-num-fields argc))
2557+
(some? known-num-fields)
2558+
(not (or (= known-num-fields argc)
2559+
(and (:record ctor-var)
2560+
(= (+ 2 known-num-fields) argc)))))
25582561
(warning :fn-arity env {:argc argc :ctor ctor}))
25592562
{:env env :op :new :form form :class ctorexpr :args argexprs
25602563
:children [:class :args]

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,3 +1492,23 @@
14921492
'[(ns test.foo
14931493
(:import goog))]))
14941494
(is (= {} (get-in @cenv [::ana/namespaces 'test.foo :imports])))))
1495+
1496+
(deftest test-cljs-3371
1497+
(let [ws (atom [])]
1498+
(ana/with-warning-handlers [(collecting-warning-handler ws)]
1499+
(env/with-compiler-env @test-cenv
1500+
(analyze (ana/empty-env)
1501+
'(do
1502+
(defrecord Foo [a])
1503+
(Foo. nil)
1504+
(Foo. nil nil nil)))))
1505+
(is (empty? @ws)))
1506+
(let [ws (atom [])]
1507+
(ana/with-warning-handlers [(collecting-warning-handler ws)]
1508+
(env/with-compiler-env @test-cenv
1509+
(analyze (ana/empty-env)
1510+
'(do
1511+
(defrecord Foo [a])
1512+
(Foo. nil nil)))))
1513+
(is (= 1 (count @ws)))
1514+
(is (string/starts-with? (first @ws) "Wrong number of args (2) passed to Foo"))))

0 commit comments

Comments
 (0)