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-14092] Polish experience for adding protocol stubs #56478

Open
typesanitizer opened this issue Jan 23, 2021 · 3 comments
Open

[SR-14092] Polish experience for adding protocol stubs #56478

typesanitizer opened this issue Jan 23, 2021 · 3 comments
Labels
compiler The Swift compiler in itself improvement

Comments

@typesanitizer
Copy link

Previous ID SR-14092
Radar rdar://problem/73526413
Original Reporter @typesanitizer
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: 1665b5142f4d5da0d721b8952c21bc92

Issue Description:

Tested with Swift 5.3.2 (Xcode 12.3, build 12C33)

Consider the following code:

import SwiftUI
 
struct MyScrollView: NSViewRepresentable {
}

Xcode suggests adding protocol stubs. If you use the fix-it, then it will add in typealias NSViewType = <#type#>.

If you don't write the type: Xcode will suggest adding protocol stubs and if you click Fix, it will add another typealias NSViewType = <#type#>.

If you do write the type, it will still suggest adding protocol stubs. If you click Fix, now it adds stubs for func makeNSView and func updateNSView.

It would be nice if:

  1. We didn't add a duplicate stub in case there's an error (easy mistake to make if you're going too fast).

  2. Add all the stubs at once, instead of going back-and-forth.

@typesanitizer
Copy link
Author

@swift-ci create

@typesanitizer
Copy link
Author

Another problem is that the subsequent stubs that get added use the newly created type <#type#>. IMO, it should instead use the typealias NSViewType because that helps prevent the signature from becoming invalidated in case you change what the typealias NSViewType is referring to.

@natecook1000
Copy link
Member

It might make sense to de-prioritize type aliases — those can often get picked up from other requirements, so they end up not being necessary. For example, when you conform to the Sequence protocol, the `Iterator` type nearly always gets inferred from the `makeIterator()` requirement's return type.

@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
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

2 participants