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-11653] Type inference fails when using dynamic keypath lookup syntax #54064

Open
swift-ci opened this issue Oct 23, 2019 · 1 comment
Open
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

@swift-ci
Copy link
Collaborator

Previous ID SR-11653
Radar rdar://problem/56543016
Original Reporter Anandabits (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: dcc1d4badd52b9cb30098d0285a02e10

Issue Description:

The code sample below demonstrates an issue in Xcode 11.2 beta 2 where type inference works when a dynamic member subscript is written explicitly but fails when using dynamic key path lookup syntax. As a syntactic sugar feature, it is expected that type inference behaves identically to the explicitly written subscript.

protocol P {}
struct S: P {}
struct Wrapper<T: P>: Hashable {}
extension Wrapper where T == S {
    static func foo(_: String) -> Self { .init() }
}
struct Wrapper2<T: P> {}
struct Context {
    let generic: GenericSubscript
}
struct GenericSubscript {
    subscript <T: P> (t: Wrapper<T>) -> Wrapper2<T> {
        .init()
    }
}

@dynamicMemberLookup
struct DynamicKeypath {
    subscript <T: P> (dynamicMember path: KeyPath<Context, Wrapper2<T>>) -> String {
        ""
    }
}
func test(dynamic: DynamicKeypath) {
   // works
   let s =  dynamic[dynamicMember: \.generic[.foo("")]]
   // Generic parameter 'T' could not be inferred
   let s2 = dynamic.generic[.foo("")]
}
@belkadan
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