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

Optional-chained key path into nested optional returns wrong value #76510

Open
stephencelis opened this issue Sep 17, 2024 · 1 comment
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@stephencelis
Copy link
Contributor

Description

Where an optional-chained key path to a nested optional should return nil, it somehow returns .some(nil) instead.

Reproduction

import Testing

@Test
func optionalChainedKeyPathToNestedOptional() {
  struct A {
    var str: String??
  }
  struct B {
    var a: A?
  }
  let b = B()
  #expect(b.a?.str == String??.none)              // ✅
  #expect(b[keyPath: \.a?.str] == String??.none)  // 🛑
  // .some(nil) != .none
}

Expected behavior

I expect the key path access to return the correct value.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0

Additional information

No response

@stephencelis stephencelis added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Sep 17, 2024
@stephencelis
Copy link
Contributor Author

@Azoy This bug potentially overlaps with some of the key path performance issues you were working on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant