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

Fix Optional implementation for ConstructibleFromJSValue #238

Merged
merged 1 commit into from Apr 5, 2024

Conversation

omochi
Copy link
Contributor

@omochi omochi commented Apr 5, 2024

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
17 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
Development

Successfully merging this pull request may close these issues.

None yet

2 participants