rescript-lang / rescript-lang/rescript

Invalid function call in generated output

Open
#8,153 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
OCaml
Stars
7.5k
Forks
485
Avg merge
1d 2h
Merged PRs (30d)
55

Description

// External binding to global "test"
@val external _test: (string, (unit => unit) => unit) => unit = "test"

// Wrapper function shadows the external's target name
let test = (name, callback) => {
  _test(name, _done => callback())
}

// BUG: This should call global test(), but calls local wrapper instead
let broken = () => {
  _test("async", done => done())
}

Generates:

// Generated by ReScript, PLEASE EDIT WITH CARE


function test(name, callback) {
  globalThis.test(name, _done => callback());
}

function broken() {
  test("async", done => done());
}

export {
  test,
  broken,
}
/* No side effect */

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce issue 8153 using the embedded ReScript source and inspect the compiler’s generated JavaScript around test and broken. Compare the emitted call with the external binding’s global target; done means broken() preserves the intended globalThis.test() call rather than resolving to the local wrapper.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, ocaml
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.