-
-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potentially eliminating the case of === #856
Comments
This turns out to be a bigger feat than expected. Because function test(): string {
if (a !== null) return a; // now results in an "is possibly null" error
return "";
} This a more general issue under the hood that we already have with anything that implements custom |
The easiest solution seems to be to do the identity check as an additional one to overloads that one can't override, looking somewhat like // equality
i32.eq(a, b) ? true : A#__eq(a, b)
// inequality
i32.eq(a, b) ? false : A#__ne(a, b) but that will limit what the overloads can do in the identity-equal case and introduces a branch. A proper but radical solution would be to drop support for overloads entirely and build string comparison into the compiler, with alternative solutions going into the direction of building our own interpreter. A half-baked solution would be to disallow overriding |
Currently thinking about moving null checking to the type system, adding a third reference type variant |
Why not just introduce a new operator? I think this would avoid the confusion and probably be easier to implement too. For example:
There could also be a negative form:
...although of course that would be for convenience/readability, since |
...When I wrote the above, I forgot about the fact that |
I'm expecting my AssemblyScript code to compile as TypeScript and produce a JavaScript program that works as a drop in replacement for the WebAssembly module. Both modules should ( eventually ) support loading with |
It has been suggested various times to align the use of the
===
operator to what JS/TS would do, which came also up again in a recent issue (I don't remember which one), suggesting to replace our special===
semantics withchangetype<usize>(a) == changetype<usize>(b)
in standard library code, which is about the only place where this is of importance. Overall this change would make===
and==
behave exactly the same for string operands and drop the special meaning ofsomeObject === someObject
, replacing it with something else where necessary.Considering the general confusion introduced by this, I am leaning towards this solution. Thoughts?
The text was updated successfully, but these errors were encountered: