Welcome! Please see the About page for a little more info on how this works.
In the following, the first and last should throw:
cljs.user=> (set! *print-fn-bodies*) nil cljs.user=> (set! *print-fn-bodies* true) true cljs.user=> (set! target -prop 3) true cljs.user=> (set! *print-fn-bodies* true false true) true
Implementation guidance:
The message thrown should be derived from Clojure, perhaps "Malformed assignment, expecting (set! target val) or (set! target -prop val)"
The check and throw can be added to the analyzer's code which parses 'set!: https://github.com/clojure/clojurescript/blob/6eedd0a08c49f7b0d4dcb30977b2fb38c90577bd/src/main/clojure/cljs/analyzer.cljc#L2229
'set!
An example of a similar throw is in the analyzer code for {{'if}}: https://github.com/clojure/clojurescript/blob/6eedd0a08c49f7b0d4dcb30977b2fb38c90577bd/src/main/clojure/cljs/analyzer.cljc#L1446-L1449
Tests can be added in {{cljs.analyzer-tests}} (which is run via {{lein test}}): https://github.com/clojure/clojurescript/blob/master/src/test/clojure/cljs/analyzer_tests.clj
Comment made by: namenu
set! supports 3-arity form so error message from Clojure could be syntatically wrong.
set!
Is it ok to throw an error just like {{'if}}?
Comment made by: thheller
The code suggests that passing 3 args is actually valid.
(set! o -prop val) (set! (.-prop o) val)
Comment made by: mfikes
Ahh, right Thomas. I'll update the description.
Hyunwoo: Yes
Comment made by: sulami
This should do it (I hope). Verified that it builds and works on my machine with all projects I have.
Hi Robin. Thanks for your contribution. Have you signed the CA?
I just have, yes.
CLJS-2923.patch LGTM. It behaves properly, and passes in CI and Canary tests.