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-14011] Guide existential uses of non-existential protocols toward generic parameterization #56404

Open
CodaFi opened this issue Jan 5, 2021 · 0 comments
Labels
compiler The Swift compiler in itself improvement

Comments

@CodaFi
Copy link
Member

CodaFi commented Jan 5, 2021

Previous ID SR-14011
Radar rdar://72786075
Original Reporter @CodaFi
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: a3dae738ebde8ba9413ccc614390b5bd

Issue Description:

It’s common for folks to reach for existentials in places we don’t allow them, e.g.,

struct ContainerView: View {
    var childView: View   // error: Protocol ‘View’ can only be used as a generic constraint because it has Self or associated type requirements
  }

In some common scenarios, such as stored properties of a struct, cases of an enum, or parameters of a function, the answer is to parameterize the enclosing entity, e.g.,

  struct ContainerView<V: View>: View {
    var childView: V
  }

Can we suggest such a transformation as a Fix-It to help the user along?

@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

1 participant