rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

@uncurry in external function causes extra 'param' to be emitted in curried mode of ReScript 11

Open TheSpyder opened this issue 1 year ago • 3 comments

Thank you for filing! Check list:

  • [x] Is it a bug? Usage questions should often be asked in the forum instead.
  • [x] Concise, focused, friendly issue title & description.
  • [x] A minimal, reproducible example.
  • [x] ~OS and browser versions, if relevant.~ not browser specific
  • [x] ~Is it already fixed in master? Instructions~ no

First reported in 11.0.0-rc4 https://github.com/glennsl/rescript-jest/issues/119

The example code works in ReScript 10, and 11, but not 11 with "uncurried": false set. In that mode an unnecessary param argument is emitted for the call to the test external - I've added an exception when this happens, but in rescript-jest this causes jest to think it's an async test and wait for a callback incorrectly.

The workaround is to drop the @uncurry (which I've demonstrated with the _testPass external) and use manual uncurried functions. If you comment out the _testFail call it works in all 3 compilers.

To me that suggests a bug with @uncurry in 11?

Example code:

let test = %raw(`
  (name, fn) => {
    if (fn.length > 0) throw "invalid function"
    else console.log('running test "', name, '", result:', fn())
  }
`)

module Test: {
  let runTest: (string, unit => unit) => unit
} = {
  @val external _testFail: (string, @uncurry (unit => Js.undefined<unit>)) => unit = "test"
  @val external _testPass: (string, (. unit) => Js.undefined<unit>) => unit = "test"

  let runTest = (name, fn) => {
    _testFail(name, () => {
      fn()
      Js.log("after test run")
      Js.undefined
    })

    _testPass(name, (. ()) => {
      fn()
      Js.log("after test run")
      Js.undefined
    })
  }
}

let _ = Test.runTest("my test", () => Js.log("my test is running"))

TheSpyder avatar Apr 18 '24 03:04 TheSpyder

Incidentally I ran in the exact same issue at the exact same time. It causes almost all tests to fail for us, because Jest relies on arity. Repro of the behavior here (I found some variants of this behavior here):

https://github.com/jfrolich/rescript-11-uncurry-bug/blob/master/src/App.res#L14

jfrolich avatar Apr 18 '24 14:04 jfrolich

Any plan to fix this?

konradtho avatar Jun 06 '24 12:06 konradtho

They're removing curried mode in v12, so it seems unlikely.

TheSpyder avatar Jun 06 '24 13:06 TheSpyder

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jun 02 '25 02:06 github-actions[bot]