AssemblyScript / assemblyscript

A TypeScript-like language for WebAssembly.
https://www.assemblyscript.org
Apache License 2.0
16.79k stars 655 forks source link

Add a built function `refEqual<T>(a: T, b:T)` to always compare ref equality #2668

Open yjhmelody opened 1 year ago

yjhmelody commented 1 year ago

Feature suggestion

When meet == operator overload. There is no way to know if the ref is same.

For reference type, it's very helpful to know the ref equality in many scenarios. For value equality, we want to compare whether the values are equal. For example, as an index key, it is impossible to rely on comparison references, because the external key is newly constructed by itself. But we still need the ref equality for such type.

BTW, use === to represent this sematic is fine.

MaxGraey commented 1 year ago

What's wrong with this approach?

const isEqRefs = changetype<usize>(obj1) == changetype<usize>(obj2)
yjhmelody commented 1 year ago

What's wrong with this approach?


const isEqRefs = changetype<usize>(obj1) == changetype<usize>(obj2)

its ok,but should be builtin