Are unsigned types fully supported on JS? I was tr...
# javascript
m
Are unsigned types fully supported on JS? I was trying to use them but I ran into a strange error:
Copy code
fun main() {
    ubyteArrayOf(
        *listOf(ubyteArrayOf())[0]
    )
}
results in:
Copy code
Unhandled JavaScript exception: listOf(...).get_c1px32_k$(...).slice is not a function
https://pl.kotl.in/nEyBqjkBZ The same code works just fine when replacing
ubyteArrayOf
with
byteArrayOf
or running it on JVM instead.
👀 2
e
A
UByteArray
is just a
Int8Array
under the hood, just treated differently at runtime. This works:
Copy code
fun main() {
  val array = listOf(UByteArray(16) { 0u })[0]
  ubyteArrayOf(*array)
}
So to me it's a compiler bug.
m
Ah, alright. Then I will just rewrite the code like that. Thanks!
e
Yup, could you also open an issue? Or do you want me to do it?
m
I don't have an account on the bug tracker, so I would appreciate if you could do it. Thanks!
e
Np.
There is a missing .storage call with your example. This is what gets generated when you extract the expression:
Copy code
listOf(new UByteArray(tmp$ret$0)).get_c1px32_k$(0).storage_1
So yeah this is clearly a bug.
m
Weird that it works if you extract the variable. I noticed this bug in my code when adding one destructuring thingy in a bigger UByteArray initialisation, and I think it even deleted bytes and made the array shorter? I tried to get a minimal example going, and there I could only observe this crash...
Nevermind, this replicates it:
Copy code
fun main() {
    println(
        ubyteArrayOf(
            *UByteArray(16) { 0u },
            *listOf(ubyteArrayOf())[0],
        ).joinToString(prefix = "[", postfix = "]")
    )
}
The array is just empty when doing this. Without the extra array it throws the same issue as before.
e
This is enough as a reproducer I think:
Copy code
ubyteArrayOf(*listOf(ubyteArrayOf())[0])
m
Right, it's probably the same issue.