Share your thoughts in the 2021 Clojure Community Survey!

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

cljs.user=> (defmulti f identity)
cljs.user=> (defmethod f :a [x] ^:m #(vector x))
Unexpected token 'return'
SyntaxError: Unexpected token 'return'
    at cljs$js$js_eval (
    at cljs$js$eval_str_STAR__$_compile_loop (
    at Object.cljs$js$eval_str_STAR_ [as eval_str_STAR_] (
    at Function.cljs.js.eval_str.cljs$core$IFn$_invoke$arity$5 (
    at Function.cljs_bootstrap.core.read_eval_print.cljs$core$IFn$_invoke$arity$3 (
    at Function.cljs_bootstrap.core.read_eval_print.cljs$core$IFn$_invoke$arity$2 (
    at Object.cljs_bootstrap$core$read_eval_print [as read_eval_print] (
    at handler (
    at e (
    at i._HandleEnter (
    at i._HandleKey (
    at HTMLTextAreaElement.<anonymous> (
    at HTMLTextAreaElement.dispatch (
    at HTMLTextAreaElement.u (

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

Yes please open a JIRA issue. Thanks!

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:
0 votes