Skip to content

fix(knoi): convert JS Number arrays to Kotlin Int without silent zeros - #54

Closed
tonycoder-hub wants to merge 2 commits into
Tencent-TDS:masterfrom
tonycoder-hub:cursor/knoi-array-int-conversion-cc31
Closed

tonycoder-hub wants to merge 2 commits into
Tencent-TDS:masterfrom
tonycoder-hub:cursor/knoi-array-int-conversion-cc31

Conversation

@tonycoder-hub

Copy link
Copy Markdown

Summary

  • ArkTS Array received as Kotlin Array became all zeros after toIntArray(). Array worked because JS Number is IEEE-754 double.
  • Read JS Number as double, then toInt()/toLong(), instead of napi_get_value_int32 or reinterpreting Float64 bytes as i32.
  • Coerce generated Array/List parameters so type-erased Double elements become real Kotlin ints. Int stays a supported type.

Test plan

  • JsNumberConversionTest: Double array to Int, toIntArray(), reject non-numbers
  • NumericCollectionConvertTest: processor only coerces numeric Array/List
  • Sample harness testArrayIntReturnArrayInt

Fixes #25

JS Array<number> was arriving as Array<Double> due to type erasure, so
Array<Int>.toIntArray() unboxed Doubles as Int and produced all zeros.
Convert Number via toInt() after double, read Int32Array as i32, and
coerce generated Array/List<Int> parameters.

Co-authored-by: Tony Jin <407243179@qq.com>
@tencent-adm

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Avoid Object[]-as-Integer[] on JVM and keep untyped JS Array
inference on ListTypeConverter.

Co-authored-by: Tony Jin <407243179@qq.com>
@tonycoder-hub

Copy link
Copy Markdown
Author

Closing; we will not complete the required contributor agreement.

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

Successfully merging this pull request may close these issues.

knoi 数组中 Int 类型转换问题

3 participants