Skip to content

Dynamic member lookup does not honor sendability of key paths #77105

Open
@stephencelis

Description

@stephencelis

Description

If a dynamic member subscript is limited to sendable key paths, this check is only performed when invoking the dynamic member directly.

Reproduction

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

public struct Foo {
  subscript<T>(bar bar: T) -> Int { 42 }
}

public struct NonSendable: Hashable {}

func f() {
  let s = S<Foo>()
  s[dynamicMember: \.[bar: NonSendable()]]  // ❌ Fails to compile
  s[bar: NonSendable()]                     // ✅ Compiles when it shouldn't
}

Expected behavior

I expect both lines to fail to compiles.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @dynamicMemberLookupFeature → attributes: the @dynamicMemberLookup attributebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language featuresexpressionsFeature: expressionstype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions