Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Fix test failures caused by Optional: KeyPathIterable conformance #1090

Merged

Conversation

efremale
Copy link
Contributor

@efremale efremale commented Sep 23, 2020

swiftlang/swift#33992 added Optional: KeyPathIterable conformance.

The added conformance caused code parts like self[keyPath: kp] as? _KeyPathIterableBase to be interpreted as casting Optional (return type of self[keyPath: kp]) to _KeyPathIterableBase (which always succeeds because of the added conformance).

The original intention was to cast the wrapped value of Optional to _KeyPathIterableBase. This original behavior is restored by changing
if let nested = self[keyPath: kp] as? _KeyPathIterableBase to
if let value = self[keyPath: kp], let nested = value as? _KeyPathIterableBase,
where value first "unwraps" Optional and nested is the result of casting wrapped value to _KeyPathIterableBase.

swiftlang/swift#33992 added `Optional: KeyPathIterable` conformance.
The added conformance caused code parts like `self[keyPath: kp] as? _KeyPathIterableBase`
to be interpreted as casting `Optional` (return type of `self[keyPath: kp]`) to
`_KeyPathIterableBase` (which always succeeds because of the added conformance).

The original intention was to cast the wrapped value of `Optional` to `_KeyPathIterableBase`.
This original behavior is restored by changing
`if let nested = self[keyPath: kp] as? _KeyPathIterableBase` to
`if let value = self[keyPath: kp], let nested = value as? _KeyPathIterableBase`,
where `value` first "unwraps" `Optional` and `nested` is the result of casting wrapped
value to `_KeyPathIterableBase`.
@xihui-wu xihui-wu merged commit 4c60186 into tensorflow:master Sep 25, 2020
texasmichelle added a commit to texasmichelle/swift-apis that referenced this pull request Oct 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants