Comment made by: dpsutton
This doesn't require different namespaces. The bug is that let-fn
is putting its binding as a global variable.
And easy reproduction is
1. lein new mies letfn-bug
,
2. update cljs version to (link: org.clojure/clojurescript "1.9.946")
3. and then
`
(ns letfn-bug.core
(:require [clojure.browser.repl :as repl]))
(enable-console-print!)
(letfn [(non-unique-name [] 4)]
(defn f1 [] (non-unique-name)))
(letfn [(non-unique-name [] 5)]
(defn f2 [] (non-unique-name)))
(println "should be 4-> " (f1))
(println "should be 5-> " (f2))
`
then scripts/repl
.
results in:
`
cljs.user=> (load-file "letfn_bug/core.cljs")
should be 4-> 5
should be 5-> 5
nil
cljs.user=>
`
With the generated js:
// Compiled by ClojureScript 1.9.946 {}
goog.provide('letfn_bug.core');
goog.require('cljs.core');
goog.require('clojure.browser.repl');
cljs.core.enable_console_print_BANG_.call(null);
var non_unique_name = (function letfn_bug$core$non_unique_name(){
return (4);
});
letfn_bug.core.f1 = (function letfn_bug$core$f1(){
return non_unique_name.call(null);
});
var non_unique_name = (function letfn_bug$core$non_unique_name(){
return (5);
});
letfn_bug.core.f2 = (function letfn_bug$core$f2(){
return non_unique_name.call(null);
});
cljs.core.println.call(null,"should be 4-> ",letfn_bug.core.f1.call(null));
cljs.core.println.call(null,"should be 5-> ",letfn_bug.core.f2.call(null));