Closed rbsdc closed 2 years ago
How are you calling testFunctionLong
? From JavaScript? So long
in Java is not number
it is goog.math.Long
, and it has a subtract
method.
@rluble thank you for the reply. Yes, I called it from Javascript. First, I export the functions as follows:
goog.exportSymbol('Test.testFunctionInt', Test.testFunctionInt);
goog.exportSymbol('Test.testFunctionLong', Test.testFunctionLong);
Then I call them from JavaScript like this:
console.log(Test.testFunctionInt(10000, 9500, 1000));
console.log(Test.testFunctionLong(10000, 9500, 1000));
As to your remark:
So long in Java is not number it is goog.math.Long, and it has a subtract method.
Right, this should be the case, or else calling "subtract" on a non-object would always fail. That is, module$exports$vmbootstrap$LongUtils$impl.m_toNativeLong__java_lang_Object(a)
should return a object in the transpiled code, but returns a number.
console.log(Test.testFunctionLong(10000, 9500, 1000));
It would be a bug to invoke your testFunctionLong
in this way, as the first two arguments to testFunctionLong
must be goog.math.Long
values and not plain JS Number
values.
Try instead to export the goog.math.Long.fromInt
function to correctly call this:
console.log(Test.testFunctionLong(goog.math.Long.fromInt(10000, goog.math.Long.fromInt(9500), 1000));
Note that if instead of exporting your functions you had instead called them from another JS file that closure read, typechecked, compiled, it would have reported this at compile time.
Thank you, again!
The following works when transpiled to JavaScript:
The following, however, does not work:
Here, the following error is thrown:
The error can be traced back to the following code:
Here,
module$exports$vmbootstrap$LongUtils$impl.m_toNativeLong__java_lang_Object(a)
returns a number (e.g.500
). As such, it has no methodsubtract
, which is why aTypeError
is thrown.Bazel version 5.1.0