Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 tasks done
TheSpyder opened this issue Apr 18, 2024 · 1 comment

Comments

@TheSpyder
Copy link
Contributor

Thank you for filing! Check list:

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

First reported in 11.0.0-rc4 glennsl/rescript-jest#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"))
@jfrolich
Copy link

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

TheSpyder added a commit to TheSpyder/rescript-atdgen-codec-runtime that referenced this issue Apr 19, 2024
…t-jest. Unfortunately, due to rescript-lang/rescript-compiler#6729 this means the project is stuck on ReScript 10.
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

No branches or pull requests

2 participants