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

[SR-11955] Cannot chain key path dynamic member subscripts #54375

Open
hamishknight opened this issue Dec 14, 2019 · 1 comment
Open

[SR-11955] Cannot chain key path dynamic member subscripts #54375

hamishknight opened this issue Dec 14, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-11955
Radar rdar://problem/58435668
Original Reporter @hamishknight
Type Bug
Environment

Swift version 5.2-dev (Swift 7cdb285)
Target: x86_64-apple-darwin19.0.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 55ca75a77b438338ccb55a570c89d580

Issue Description:

We allow the chaining of key path dynamic members for a reference to a property, for example:

struct Q {
  var i = 0
}

@dynamicMemberLookup
struct R {
  subscript(dynamicMember kp: KeyPath<Q, Int>) -> Int { 0 }
}

@dynamicMemberLookup
struct S {
  subscript(dynamicMember kp: KeyPath<R, Int>) -> Int { 0 }
}

func foo(_ x: S) {
  _ = x.i
}

However we don't appear to be able to the same for subscripts:

struct Q {
  subscript(_ x: Int) -> Int { 0 }
}

@dynamicMemberLookup
struct R {
  subscript(dynamicMember kp: KeyPath<Q, Int>) -> Int { 0 }
}

@dynamicMemberLookup
struct S {
  subscript(dynamicMember kp: KeyPath<R, Int>) -> Int { 0 }
}

func foo(_ x: S) {
  _ = x[0] // error: Cannot convert value of type 'Int' to expected argument type 'KeyPath<R, Int>'
}
@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants