Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there, I found a bug in
is(_:)
.In version 1.2.0, the handling of optional associated values has been improved. Specifically, the subscript(case:) now correctly returns a value without unnecessarily wrapping it in an additional Optional layer when the associated value is already an Optional. However, this improvement has introduced a significant bug.
Consider the following enum as an example:
When using the is(_:) method with c2's associated value set to nil, like so:
The expected result would be true, but it incorrectly returns false. This is a direct consequence of the changes in version 1.2.0. Prior to this change, the value of
self[case: keyPath]
used in the implementation ofis(_:)
would be Optional(nil), bug which is not nil, thus functioning correctly. However, post-change, the value ofself[case: keyPath]
becomes nil, leading to incorrect behavior even when the case matches.On the other hand, with a non-nil associated value such as:
The method works correctly because self[case: keyPath] returns "foo".
This pull request introduces a code change to prevent the execution of the line at 52 in Optional+CasePathable that was added in 1.2.0: