You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// External binding to global "test"
@valexternal_test: (string, (unit=>unit) =>unit) =>unit="test"// Wrapper function shadows the external's target namelettest= (name, callback) => {
_test(name, _done=>callback())
}
// BUG: This should call global test(), but calls local wrapper insteadletbroken= () => {
_test("async", done=>done())
}
Generates:
// Generated by ReScript, PLEASE EDIT WITH CAREfunctiontest(name,callback){globalThis.test(name,_done=>callback());}functionbroken(){test("async",done=>done());}export{test,broken,}/* No side effect */
// External binding to global "test"
@val @scope("globalThis")
external_test: (string, (unit=>unit) =>unit) =>unit="test"// Wrapper function shadows the external's target namelettest= (name, callback) => {
_test(name, _done=>callback())
}
// BUG: This should call global test(), but calls local wrapper insteadletbroken= () => {
_test("async", done=>done())
}
// Generated by ReScript, PLEASE EDIT WITH CAREfunctiontest(name,callback){globalThis.test(name,_done=>callback());}functionbroken(){globalThis.test("async",done=>done());}export{test,broken,}/* No side effect */
I suspect this was caused by #8098, which seems to have two effects in this scenario:
It rewrites test to globalThis.test, in some cases, but not all. After reading both the PR description and code, it's still unclear to me both what the intended rules and actual rules for this are.
It prevents subsequent bindings from detecting the external name as a duplicate, and therefore prevents the name mangling that previously prevented this issue from occurring.
Activity
fix: for ReScript-v12.0.2 - update external test functions to use glo…
dsiu commentedon Jan 9, 2026
Adding
@scope("globalThis")to external binding seems to fix this issue. I ain't sure if this is the righ behavior since it was introduced in v12.0.2.rescript-jest is failing because of this issue and I had to submitted a similar pull request // @glensc
glennsl commentedon Mar 1, 2026
Here's the compiler output of the code in OP from both 12.0.1 and 12.0.2, for comparison:
12.0.1:
12.0.2:
I suspect this was caused by #8098, which seems to have two effects in this scenario:
testtoglobalThis.test, in some cases, but not all. After reading both the PR description and code, it's still unclear to me both what the intended rules and actual rules for this are.Fixing either of these should solve the issue.
alex35mil commentedon Jun 22, 2026
Got bitten by this again: playground
cknitt commentedon Oct 19, 2026
This was fixed by #8785: the generated code no longer calls the shadowed local binding, it calls the external via
globalThis.test(...). Closing.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo