Skip to content

Fix #1050: refer to a munged catch binding by its gensym - #1051

Merged
borkdude merged 2 commits into
squint-cljs:mainfrom
mskyan:fix-catch-binding-munge
Oct 15, 2026
Merged

borkdude merged 2 commits into
squint-cljs:mainfrom
mskyan:fix-catch-binding-munge

Conversation

@mskyan

@mskyan mskyan commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Please answer the following questions and leave the below in as part of your PR.


Fixes #1050.

emit-special 'try munged the catch binding first and registered it in :var->ident
under the munged name. References in the catch body are looked up by the original
symbol, so a name that needs munging missed the entry and was emitted without the
gensym suffix. This PR registers the original symbol as the key and the munged
gensym as the value, the same way let does.

The new assertions in try-catch-test cover abort-error, ok?, and err!. The err! case
also has an outer let with the same name. Without the fix, all three assertions fail: the
first two with a ReferenceError, and the third because the body silently reads the outer
local. With the fix, bb test:node, bb test:bb and bb test:clj all pass locally
(Windows 11, Node 22).

`emit-special 'try` registered the catch binding in `:var->ident`
under its munged name, but references in the body are looked up by the
original symbol. A name that needs munging (e.g. `abort-error`) was
then emitted without the gensym suffix and was undefined. Register the
original symbol, as `let` does.
Comment thread src/squint/compiler_common.cljc Outdated
Less string processing, as suggested in review.
@borkdude
borkdude merged commit 827029a into squint-cljs:main Oct 15, 2026
3 checks passed
@borkdude

Copy link
Copy Markdown
Member

Thanks for your PR!

If you want to share, by any chance, what you're using squint for, I'd be happy to hear it.

@mskyan
mskyan deleted the fix-catch-binding-munge branch October 16, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

catch binding that needs munging is not found in the catch body

2 participants