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-9052] Cannot access protocol property returning Self on an existential #51555

Open
hamishknight opened this issue Oct 20, 2018 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-9052
Radar None
Original Reporter @hamishknight
Type Bug
Environment

Swift version 4.2-dev (LLVM c4a0883115, Clang 0a99881462, Swift 533575ab62)
Target: x86_64-apple-darwin17.7.0

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

md5: 96ac2f701281716b3ac14ff121110227

Issue Description:

The following doesn't compile:

protocol P {}
extension P {
  var foo: Self { return self }
}

func bar(_ x: P) {
  let y = x.foo // error: Member 'foo' cannot be used on value of protocol type 'P'; use a generic constraint instead
}

But really it ought to compile – we should erase Self back to P, just like we do with methods and subscripts:

protocol P {}
extension P {
  func foo() -> Self { return self }
  subscript(foo: String) -> Self { return self }
}

func bar(_ x: P) {
  let y = x.foo() // fine
  let z = x[""] // also fine
}
@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant