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-14029] @dynamicMemberLookup in generic type infers incorrect return type #56420

Open
WowbaggersLiquidLunch opened this issue Jan 10, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@WowbaggersLiquidLunch
Copy link
Collaborator

Previous ID SR-14029
Radar rdar://problem/73014175
Original Reporter @WowbaggersLiquidLunch
Type Bug
Environment

Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
x86_64-apple-darwin19.6.0

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

md5: 508cfdd0b2e6f53e26253db57ca0dc30

Issue Description:

@dynamicMemberLookup subscript in a generic property wrapper fails to infer the correct type when the return type is the same property wrapper type with a different parameter type.

For example:

@dynamicMemberLookup
struct T<Foo> {
    let foo: Foo
    subscript<Bar>(
        dynamicMember keyPath: WritableKeyPath<Foo, Bar>
    ) -> T<Bar> {
        T(foo: foo[keyPath: keyPath])
        // error: Cannot convert return expression of type 'T<Foo>' to return type 'T<Bar>'
        // error: Cannot convert value of type 'Bar' to expected argument type 'Foo'
        // fix-it: Insert ' as! Foo'
    }
}

relevant topics on the forums:

https://forums.swift.org/t/how-do-i-use-dynamic-member-lookup-in-a-generic-property-wrapper-to-return-the-looked-up-member-wrapped-by-the-same-property-wrapper/43725

https://forums.swift.org/t/using-the-bare-name-of-a-generic-type-within-itself/24778

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

No branches or pull requests

2 participants