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

0 votes
in ClojureScript by

The following function definitions each cause {{ERROR: JSC_DUPLICATEPARAM. Parse error. Duplicate parameter name ""}} at compile time with {{:advanced}} compilation:

`
(defn causes-duplicate-param [{_ :foo}]
(reify

Object
(a-function [-]
  (fn [] "arbitrary function inside a-function body"))))

(defn causes-duplicate-param [{- :foo}]
(reify

Object
(a-function [_]
  (fn [] "arbitrary function inside a-function body"))))

`

They generate, respectively:

`
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1601.prototype.a_function = ((function (map1599,map1599$1,_){
return (function (){
var self = this;
var = this;
return ((function (
,map
1599,map1599$1,){
return (function (){
return "arbitrary function inside a-function body";
});
;})(
,map1599,map1599_$1,))
});})(map
1599,map1599$1,_))
;

duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1612.prototype.a_function = ((function (map1610,map1610$1,_){
return (function (){
var self = this;
var = this;
return ((function (
,map
1610,map1610$1,){
return (function (){
return "arbitrary function inside a-function body";
});
;})(
,map1610,map1610_$1,))
});})(map
1610,map1610$1,_))
;
`

(Notice the duplicate {{_}} param on the 5th line of each.)

The following do not:

`
(defn causes-duplicate-param [{- :foo}]
(reify

Object
(a-function [-]
  (fn [] "arbitrary function inside a-function body"))))

(defn causes-duplicate-param [{_ :foo}]
(reify

Object
(a-function [_]
  (fn [] "arbitrary function inside a-function body"))))

`

They generate:

`
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1601.prototype.a_function = ((function (map1599,map1599$1,_){
return (function (){
var self_ = this;
var
$1 = this;
return ((function (_$1,map1599,map1599_$1,){
return (function (){
return "arbitrary function inside a-function body";
});
;})(
_$1,map1599,map1599_$1,))
});})(map1599,map1599_$1,))
;

duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1612.prototype.a_function = ((function (map1610,map1610$1,_){
return (function (){
var self_ = this;
var
$1 = this;
return ((function (_$1,map1610,map1610_$1,){
return (function (){
return "arbitrary function inside a-function body";
});
;})(
_$1,map1610,map1610_$1,))
});})(map1610,map1610_$1,))
;
`

(Notice that one of the {{_}} params has become {{___$1}}.)

My guess, though I haven't looked into the compiler code, is that the compiler escapes {{_}} to {{__$1}} when it would conflict with another {{}}, and also it translates {{-}} to {{_}}, but it doesn't notice the conflict when the ClojureScript symbols are different.

3 Answers

0 votes
by

Comment made by: peeja

Forgive the weird formatting errors. I couldn't find a preview function and there doesn't appear to be a way to edit the issue now that it's posted.

0 votes
by

Comment made by: dnolen

This is because of munging they will become the same thing. Patch welcome.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-1575 (reported by alex+import)
...