We're updating the issue view to help you get more done. 

cljs.core/IFn implementations generate duplicated code

Description

Currently when defining types that implement cljs.core/IFn a protocol fn is generated as well as a .call method that repeats the entire code instead of dispatching to the generated protocol fn.

1 2 3 4 (deftype InvokeTest [a b] IFn (-invoke [_] (+ a b)))
1 2 3 4 5 cljs.user.InvokeTest.prototype.cljs$core$IFn$_invoke$arity$0 = function() { var self__ = this; var _ = this; return self__.a + self__.b; };

.call repeats all code instead of calling this.cljs$core$IFn$_invoke$arity$<n>. Multiple arities repeat the code for each arity.

1 2 3 4 5 6 cljs.user.InvokeTest.prototype.call = function(self__) { var self__ = this; var self____$1 = this; var _ = self____$1; return self__.a + self__.b; };

Should be something like

1 2 3 4 5 6 7 8 9 cljs.user.InvokeTest.prototype.call = function(self__) { switch(arguments.length) { case 0: return this.cljs$core$IFn$_invoke$arity$0(); ... default: throw new Error("Invalid arity: " + arguments.length); } };

Environment

None

Status

Assignee

Unassigned

Reporter

Thomas Heller

Labels

None

Approval

None

Patch

Code and Test

Priority

Major