Uploaded image for project: 'ClojureScript'
  1. CLJS-1575

Combination of - and _ params causes JSC_DUPLICATE_PARAM

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects versions: None
    • Fix versions: None
    • Labels:
      None

      Description

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

      Unable to find source-code formatter for language: clojure. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      (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 (map__1599,map__1599__$1,_){
      return (function (){
      var self__ = this;
      var _ = this;
      return ((function (_,map__1599,map__1599__$1,_){
      return (function (){
      return "arbitrary function inside a-function body";
      });
      ;})(_,map__1599,map__1599__$1,_))
      });})(map__1599,map__1599__$1,_))
      ;
      
      duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1612.prototype.a_function = ((function (map__1610,map__1610__$1,_){
      return (function (){
      var self__ = this;
      var _ = this;
      return ((function (_,map__1610,map__1610__$1,_){
      return (function (){
      return "arbitrary function inside a-function body";
      });
      ;})(_,map__1610,map__1610__$1,_))
      });})(map__1610,map__1610__$1,_))
      ;
      

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

      The following do not:

      Unable to find source-code formatter for language: clojure. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      (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 (map__1599,map__1599__$1,_){
      return (function (){
      var self__ = this;
      var ___$1 = this;
      return ((function (___$1,map__1599,map__1599__$1,_){
      return (function (){
      return "arbitrary function inside a-function body";
      });
      ;})(___$1,map__1599,map__1599__$1,_))
      });})(map__1599,map__1599__$1,_))
      ;
      
      duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1612.prototype.a_function = ((function (map__1610,map__1610__$1,_){
      return (function (){
      var self__ = this;
      var ___$1 = this;
      return ((function (___$1,map__1610,map__1610__$1,_){
      return (function (){
      return "arbitrary function inside a-function body";
      });
      ;})(___$1,map__1610,map__1610__$1,_))
      });})(map__1610,map__1610__$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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: