Details
-
Type:
Defect
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:
-
Environment:CLJS Rhino-REPL and during Compilation
-
Patch:Code and Test
Description
`with-meta` does not working on function objects in CLJS. Compilation fails with the following error:
Error: No protocol method IWithMeta.-with-meta defined for type function: function
{
return x;
}
I tried it out on the REPL and found the following:
---------- BEGIN: repl-rhino ----------
ClojureScript:cljs.user> (with-meta #(do :foo) {:foo :bar})
"Error evaluating:" (with-meta (fn* [] (do :foo)) {:foo :bar}) :as "cljs.core.with_meta.call(null,(function (){\nreturn \"\\uFDD0'foo\";\n}),cljs.core.ObjMap.fromObject([\"\\uFDD0'foo\"],{\"\\uFDD0'foo\":\"\\uFDD0'bar\"}));\n"
org.mozilla.javascript.JavaScriptException: Error: No protocol method IWithMeta.-with-meta defined for type function:
function () {
return "\ufdd0'foo";
}
(cljs/core.cljs#222)
at cljs/core.cljs:222 (anonymous)
at cljs/core.cljs:214 (_with_meta)
at cljs/core.cljs:806 (with_meta)
at <cljs repl>:2 (anonymous)
at <cljs repl>:2
nil
---------- END: repl-rhino ----------
Reference: https://groups.google.com/forum/?fromgroups=#!topic/clojure/pRO-5IlilNM
We could create a fn wrapper type of some kind that implements all the supported arities of IFn (this means the compiler needs to guarantee that args past 20 are collected into an array-seq) that include the extra meta fields. Seems doable.