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-14284] @dynamicMemberLookup doesn't work inside extensions #56643

Open
hartbit opened this issue Feb 28, 2021 · 1 comment
Open

[SR-14284] @dynamicMemberLookup doesn't work inside extensions #56643

hartbit opened this issue Feb 28, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@hartbit
Copy link
Collaborator

hartbit commented Feb 28, 2021

Previous ID SR-14284
Radar rdar://problem/74876590
Original Reporter @hartbit
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 55c6690dac3506d9568b6b46812102fc

Issue Description:

The following example fails with a `cannot find 'name' in scope` and `cannot find 'lastName' in scope`. I would have expected it to compile and to print:

"David"
"Whatever"
"Name: David"
"Last Name: Whatever"
@dynamicMemberLookup
struct Container<T> {
    let value: T

    subscript<U>(dynamicMember keyPath: KeyPath<T, U>) -> U {
        value[keyPath: keyPath]
    }

    subscript(dynamicMember key: String) -> String {
        "Whatever"
    }
}

struct Person {
    let name: String
}

extension Container where T == Person {
    var containedName: String {
        "Name: \(name)"
    }
}

extension Container {
    var containedLastName: String {
        "Last Name: \(lastName)"
    }
}

let containedPerson = Container(value: Person(name: "David"))
print(containedPerson.name)
print(containedPerson.lastName)
print(containedPerson.containedName)
print(containedPerson.containedLastName)
@typesanitizer
Copy link

@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
Projects
None yet
Development

No branches or pull requests

2 participants