Skip to content
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

Represent JS undefined as void, not string #2291

Merged
merged 2 commits into from
May 1, 2024
Merged

Conversation

oxc
Copy link
Contributor

@oxc oxc commented May 1, 2024

Currently, JS undefined is silently converted into a string representation of Rhino's Undefined instance.
This can in theory lead to wrong function invocations if the target type is a string.

Instead, return a special undefined value with a special undefined VOID type. This prints as undefined in the console, to make it transparent what is going on.
Other than that, it behaves as void. This is consistent with JS methods returning undefined if no value was returned, and TypeScript void methods returning undefined.

To prevent any confusion, forbid undefined values from being passed to Ash functions (for now).

@oxc oxc requested a review from a team as a code owner May 1, 2024 10:43
@oxc
Copy link
Contributor Author

oxc commented May 1, 2024

That's the same test that failed last time on Windows. Seems flaky.

Currently, JS `undefined` is silently converted into a string
representation of Rhino's Undefined instance.
This can in theory lead to wrong function invocations if the target type
is a string.

Instead, return a special undefined value with a special undefined VOID
type. This prints as undefined in the console, to make it transparent
what is going on.
Other than that, it behaves as void. This is consistent with JS methods
returning `undefined` if no value was returned, and TypeScript void
methods returning `undefined`.

To prevent any confusion, forbid undefined values from being passed to
Ash functions (for now).
Copy link
Contributor

@gausie gausie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great solution

@gausie gausie enabled auto-merge (squash) May 1, 2024 11:28
@gausie gausie merged commit 982c641 into kolmafia:main May 1, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants