Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix Optional implementation for ConstructibleFromJSValue #238

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

Merged
kateinoigakukun merged 1 commit into swiftwasm:main from omochi:fix-optional-decode
Apr 5, 2024

Conversation

@omochi
Copy link
Contributor

@omochi omochi commented Apr 5, 2024
edited by kateinoigakukun
Loading

The current Optional.construct returns nil when the given JS value is null or undefined, but nilmeans a failure during decode here, so it's semantically wrong. Instead, it should return.some(nil)`.

Also, when Wrapped.construct returns nil, it means decode operation failed, so Optional.construct method should return nil. But it might be unclear that the returned Optional<Wrapped> value won't be implicitly casted to .some(nil), so I changed to return nil by guard statement explicitly.

Original description

現在の実装ではJSの値として null, undefined の場合に、
Optional.constructnil を返していますが、
これはデコードの失敗を意味するため間違っています。

適切に Optional.none がデコードできた状況なので、 .some(nil) を返す必要があります。

また、 Wrapped.constructnil を返した場合は、
デコード失敗なので nil を返すべきですが、
ここで暗黙のキャストによって .some(nil) が返ってしまうかどうか分かりづらいと思ったので、
明示的に guard 文で分岐するように書き換えてみました。

@kateinoigakukun kateinoigakukun merged commit 32538ec into swiftwasm:main Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kateinoigakukun kateinoigakukun kateinoigakukun approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /