ClojureScript

Function named same as ns fails

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

In a fresh script/repljs on clojurescript master I see the following behaviour:

ClojureScript:cljs.user> (ns foo.bar)
ClojureScript:foo.bar> (defn id [x] x)
#<
  function id(x) {
      return x;
  }
  >
  ClojureScript:foo.bar> (defn foo [] (id 42))
  #<
  function foo() {
      return foo.bar.id.call(null, 42);
  }
  >
ClojureScript:foo.bar> (foo)
  "Error evaluating:" (foo) :as "foo.bar.foo.call(null)"
  org.mozilla.javascript.EcmaError: TypeError: Cannot read property "id" from undefined (<cljs repl>#4)
      at <cljs repl>:4 (foo)
      at <cljs repl>:4 (anonymous)
      at <cljs repl>:4
 
nil
ClojureScript:foo.bar>

(https://www.refheap.com/paste/8494 in case formatting fails)

Activity

Hide
David Nolen added a comment -

Is this something you can actually recreate in a file or does this only affect REPLs?

Show
David Nolen added a comment - Is this something you can actually recreate in a file or does this only affect REPLs?
Hide
Jozef Wagner added a comment -

The bug is present always. Here is the compiled js:

goog.provide('foo.bar');
goog.require('cljs.core');
foo.bar.id = (function id(x){
return console.log(x);
});
foo.bar.foo = (function foo(){
return foo.bar.id.call(null,42); // Uncaught TypeError: Cannot read property 'id' of undefined 
});
foo.bar.foo2 = (function foo2(){
return foo.bar.id.call(null,43);
});
Show
Jozef Wagner added a comment - The bug is present always. Here is the compiled js:
goog.provide('foo.bar');
goog.require('cljs.core');
foo.bar.id = (function id(x){
return console.log(x);
});
foo.bar.foo = (function foo(){
return foo.bar.id.call(null,42); // Uncaught TypeError: Cannot read property 'id' of undefined 
});
foo.bar.foo2 = (function foo2(){
return foo.bar.id.call(null,43);
});
Hide
David Nolen added a comment -

Ah, ok I see - we have a test for the parameter case but we don't have a test for the case where the name of the fn itself matches the namespace.

Show
David Nolen added a comment - Ah, ok I see - we have a test for the parameter case but we don't have a test for the case where the name of the fn itself matches the namespace.
Hide
David Nolen added a comment -

See also CLJS-603 which shows another good test case.

Show
David Nolen added a comment - See also CLJS-603 which shows another good test case.
Hide
David Nolen added a comment - - edited
Show
David Nolen added a comment - - edited Was fixed with CLJS-544 http://github.com/clojure/clojurescript/commit/9ddf847b44ec82070e91038f4afbd8a2baec94ff, however CLJS-603 is unrelated

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: