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

Dynamic member lookup fails to autocomplete sendable key path #77035

Closed
stephencelis opened this issue Oct 15, 2024 · 3 comments · Fixed by #77691
Closed

Dynamic member lookup fails to autocomplete sendable key path #77035

stephencelis opened this issue Oct 15, 2024 · 3 comments · Fixed by #77691
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. code completion Area → source tooling: code completion

Comments

@stephencelis
Copy link
Contributor

Description

If a type with dynamic member lookup is constrained to sendable key paths, then the compiler fails to show autocomplete for the members.

Reproduction

@dynamicMemberLookup struct S<A> {
  subscript<B>(dynamicMember keyPath: KeyPath<A, B> & Sendable) -> S<B> {
    fatalError()
  }
}

func f(_ s: S<String>) {
  s.count  // Compiles, but members do not show up when autocompleting from 's.'
}

Expected behavior

I expect autocomplete to show the members.

Related bug: I can add an unavailable overload for non-sendable key paths, and it restores autocomplete, but it also allows such accesses to compile even though they should be unavailable:

extension S {
  @available(*, unavailable)
  subscript<B>(dynamicMember keyPath: KeyPath<A, B>) -> S<B> {
    fatalError()
  }
}

struct T {
  @MainActor var p = 0
}

func f(_ s: S<T>) {
  s.p  // Compiles, but it shouldn't
}

Environment

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.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 Oct 15, 2024
@stephencelis
Copy link
Contributor Author

@xedin Another key path sendability bug...

@xedin
Copy link
Contributor

xedin commented Oct 15, 2024

cc @ahoppen, this might be a code completion issue since the signature of dynamic member subscript is allowed to provide & Sendable and code completion might not handle protocol compositions correctly in some situations?…

Re: s.p that is most likely due to concurrency checker not diagnosing synthesized code, if completion issue turns up to be non-typecker I think you should file a new one for s.p example specifically.

@ahoppen ahoppen added code completion Area → source tooling: code completion and removed triage needed This issue needs more specific labels labels Oct 21, 2024
@ahoppen
Copy link
Member

ahoppen commented Oct 21, 2024

Yes, it’s indeed a code completion issue. Removing & Sendable makes the result show up.

stephencelis added a commit to pointfreeco/swift-composable-architecture that referenced this issue Oct 23, 2024
There are a few compiler bugs that prevent us from declaring sendability
for key paths where it's needed.

First, doing so breaks autocomplete, which really hurts the developer
experience: swiftlang/swift#77035

Second, even though recovering autocomplete might be preferable at the
cost of safety, there is no safety to begin with right now because
sendable diagnostics don't propagate through dynamic member lookup:
swiftlang/swift#77105

Because of this, let's only use non-sendable key paths for now, and
force cast them under the hood.
stephencelis added a commit to pointfreeco/swift-navigation that referenced this issue Oct 23, 2024
There are a few compiler bugs that prevent us from declaring sendability
for key paths where it's needed.

First, doing so breaks autocomplete, which really hurts the developer
experience: swiftlang/swift#77035

Second, even though recovering autocomplete might be preferable at the
cost of safety, there is no safety to begin with right now because
sendable diagnostics don't propagate through dynamic member lookup:
swiftlang/swift#77105

Because of this, let's only use non-sendable key paths for now, and
force cast them under the hood.
stephencelis added a commit to pointfreeco/swift-navigation that referenced this issue Oct 23, 2024
There are a few compiler bugs that prevent us from declaring sendability
for key paths where it's needed.

First, doing so breaks autocomplete, which really hurts the developer
experience: swiftlang/swift#77035

Second, even though recovering autocomplete might be preferable at the
cost of safety, there is no safety to begin with right now because
sendable diagnostics don't propagate through dynamic member lookup:
swiftlang/swift#77105

Because of this, let's only use non-sendable key paths for now, and
force cast them under the hood.
stephencelis added a commit to pointfreeco/swift-composable-architecture that referenced this issue Oct 23, 2024
* Avoid sendable key paths in dynamic member lookup

There are a few compiler bugs that prevent us from declaring sendability
for key paths where it's needed.

First, doing so breaks autocomplete, which really hurts the developer
experience: swiftlang/swift#77035

Second, even though recovering autocomplete might be preferable at the
cost of safety, there is no safety to begin with right now because
sendable diagnostics don't propagate through dynamic member lookup:
swiftlang/swift#77105

Because of this, let's only use non-sendable key paths for now, and
force cast them under the hood.

* fix
@hamishknight hamishknight self-assigned this Nov 18, 2024
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. code completion Area → source tooling: code completion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants