Repository navigation
Locals munged to the same JavaScript name (a-b, a_b) shadow each other instead of overwriting (#18) - #21
Merged
Conversation
…dow each other instead of one overwriting the other (CLJS-2461, CLJS-3426) Fixes #18
This was referenced Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18.
Locals whose names munge to the same JavaScript identifier (
a-banda_b) weren't renamed apart, so one overwrote the other (CLJS-2461, CLJS-3426). The common case is a snake_case param turned into a kebab-case local:This was a prerequisite for #14: with
const/letoutput each collision becomes a parse error.Fix
The analyzer decided that one local shadows another by comparing symbols. The new
cljs.analyzer/shadowed-localalso looks for locals in scope that munge to the same name and sets the new local's:shadowto the one with the longest shadow chain. The compiler's existing shadow renaming then emitsa_b__$1,a_b__$2, ... Picking the deepest one matters for(let [a_b 1 a-b 2 a_b 3] ...): any other choice gives the third local the same depth as the second, and they collide again.It replaces
handle-symbol-localwhere locals are bound: fn params, the fn self-name,let/loop(which also covers destructuring andcatch, which binds through alet) andletfn.letfnbindings had no:info {:shadow ...}, which the compiler reads when it renames, so they were never renamed: even(let [x 1] (letfn [(x [] 2)] ...))emittedvar xtwice. They now carry it.Code with no colliding locals compiles to exactly the same output as before, including classic
:advancedoutput: the compiler tests' output assertions and size ratchet pass unchanged. A name with no_or$can't collide with another local, so the analyzer skips the scan for it. Compiling the runtime test suite took no measurably longer (about 10.0s with the fix, 10.3s before).Tests
cljs.core-test/test-locals-munged-to-the-same-namecovers lets in return and expression position, fn params,:keysdestructuring,loop/recur, nested lets and closures,letfn,catchand reserved words (let/let$). Seven of its assertions fail onmain.test-letfn-shadowing-letcovers aletfnshadowing aletlocal.script/test-esm: 0 failures, 0 errors-M:closure:compiler.test:compiler.test.run): 0 failures, 0 errors:advanced, lite and self-host suites under Node: 0 failures, 0 errors