rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.67k stars 442 forks source link

Compiled js min/max value with bigint #7062

Open remitbri opened 3 hours ago

remitbri commented 3 hours ago

We can't use Math.min/max for bigint values.

If the rescript code is simple enough,

let a = 5n
let b = 7n
let c = max(a,b)

the compiled js is simple too:

var c = 5n > 7n ? 5n : 7n;

var a = 5n;

var b = 7n;

But if it's trickier,

let a = (x)=> BigInt.add(x, 5n)
let b = (x)=> BigInt.add(x, 7n)

let c =  max(a(4n), b(9n))

the compiled js is

import * as Caml from "./stdlib/caml.js";

function a(x) {
  return x + 5n;
}

function b(x) {
  return x + 7n;
}

var c = Caml.bigint_max(4n + 5n, 9n + 7n);

Problem:

"Property 'bigint_max' may not exist on type 'typeof import("project_path/node_modules/rescript/lib/es6/caml")'. Did you mean 'int_max'?

zth commented 3 hours ago

Thanks for the report!

Who's best to look at this, @mununki perhaps?