Navigation Menu

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-13376] Property wrapper typealias defined in protocol-extension is not resolved correctly. #55816

Open
swift-ci opened this issue Aug 10, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself property wrappers Feature: property wrappers type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13376
Radar rdar://problem/67361269
Original Reporter Vatsal Manot (JIRA User)
Type Bug
Environment

Big Sur developer beta 4
Xcode 12 beta 4
Swift 5.3

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

md5: 0e20853ceeffae474ce696885650b09f

Issue Description:

The example below demonstrates the bug. Here, Bar is used both as a top-level name for a protocol, and a name for a typealias to a property wrapper (defined in a protocol extension).

When using property wrappers, the Bar typealias is expected to resolve to the property wrapper but instead it resolves to the top-level protocol.

In the following example, "x0" will not compile while "x1" will - even though they semantically point to the same property wrapper.

protocol Bar {

{{ }}

{{}}}

{{ }}

@propertyWrapper

struct Baz: Bar {

{{ var wrappedValue: Void}}

{{ }}

{{ init() {}}

{{ wrappedValue = ()}}

    }

{{}}}

{{ }}

protocol FooProtocol {

{{ }}

{{}}}

{{ }}

extension FooProtocol {

{{ typealias Bar = Baz}}

{{ typealias BarNonConflictingName = Baz}}

{{}}}

{{ }}

struct Foo: FooProtocol {

{{ @bar var x0: Void}}

{{ @BarNonConflictingName var x1: Void}}

{{}}}

@theblixguy
Copy link
Collaborator

Hmm, it seems like we're incorrectly computing the type of the backing storage. We do correctly find the nominal type associated with the attribute (because we look for protocol members as well), but it looks like during type resolution for the attribute, we're calling resolveTopLevelIdentTypeComponent which finds protocol Bar only. I think we should be including protocol members as well, so we can find the typealias Bar.

@swift-ci
Copy link
Collaborator Author

Comment by Vatsal Manot (JIRA)

@theblixguy is this an easy fix? I'm afraid I don't have much C++ experience, but if it's an easy patch I can try my hand at it.

@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 property wrappers Feature: property wrappers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants