Welcome! Please see the About page for a little more info on how this works.

+1 vote
in ClojureScript by
retagged by

In ClojureScript 1.10.597, when I define a multimethod that returns an anonymous fn with metadata on it, I get a SyntaxError.

(defmulti f identity)
(defmethod f :a [x] ^:m #(vector x))

I get: SyntaxError: Unexpected token 'return'
The relevant compiled js is:

... cljs.core.with_meta(return (function (){...

REPL session via http://clojurescript.net/

cljs.user=> (defmulti f identity)
#'cljs.user/f
cljs.user=> (defmethod f :a [x] ^:m #(vector x))
Unexpected token 'return'
SyntaxError: Unexpected token 'return'
    at cljs$js$js_eval (http://kanaka.github.io/cljs-bootstrap/web/repl-web.js:53434:15)
    at http://kanaka.github.io/cljs-bootstrap/web/repl-web.js:54766:279
    at http://kanaka.github.io/cljs-bootstrap/web/repl-web.js:54771:22
    at cljs$js$eval_str_STAR__$_compile_loop (http://kanaka.github.io/cljs-bootstrap/web/repl-web.js:54781:24)
    at Object.cljs$js$eval_str_STAR_ [as eval_str_STAR_] (http://kanaka.github.io/cljs-bootstrap/web/repl-web.js:54796:49)
    at Function.cljs.js.eval_str.cljs$core$IFn$_invoke$arity$5 (http://kanaka.github.io/cljs-bootstrap/web/repl-web.js:54854:18)
    at Function.cljs_bootstrap.core.read_eval_print.cljs$core$IFn$_invoke$arity$3 (http://kanaka.github.io/cljs-bootstrap/web/repl-web.js:58775:33)
    at Function.cljs_bootstrap.core.read_eval_print.cljs$core$IFn$_invoke$arity$2 (http://kanaka.github.io/cljs-bootstrap/web/repl-web.js:58706:46)
    at Object.cljs_bootstrap$core$read_eval_print [as read_eval_print] (http://kanaka.github.io/cljs-bootstrap/web/repl-web.js:58695:50)
    at handler (http://kanaka.github.io/cljs-bootstrap/web/repl-main.js:47:29)
    at e (http://kanaka.github.io/cljs-bootstrap/web/jqconsole.min.js:1:16732)
    at i._HandleEnter (http://kanaka.github.io/cljs-bootstrap/web/jqconsole.min.js:1:16911)
    at i._HandleKey (http://kanaka.github.io/cljs-bootstrap/web/jqconsole.min.js:1:15169)
    at HTMLTextAreaElement.<anonymous> (http://kanaka.github.io/cljs-bootstrap/web/jqconsole.min.js:1:134)
    at HTMLTextAreaElement.dispatch (https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js:2:38053)
    at HTMLTextAreaElement.u (https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js:2:33916)
cljs.user=> 

The issue can be worked-around with an extra let:

(defmethod f :a [x] (let [g ^:m #(vector x)] g))

Nevertheless we should get this into Jira.

2 Answers

0 votes
by

Yes please open a JIRA issue. Thanks!

by
David, in general, the preferred process is for people to ask questions here - generally most users do not have jira accounts (these are a finite resource so we reserve jira accounts to contributors filing patches). So this is really on "us" (maintainers). Process doc'ed here: https://clojure.org/community/contributing#_reporting_problems_and_requesting_enhancements
0 votes
by
...