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

Sema: Ban uncallable protocol member operators #73204

Merged
merged 1 commit into from Apr 23, 2024

Conversation

slavapestov
Copy link
Member

Member operators of concrete nominal types must declare at least one parameter with that type, like

struct S {
  static func +(lhs: S, rhs: Int) -> S {}
}

For protocol member operators, we would look for a parameter of type Self, or an existential type any P. While the latter was consistent with the concrete nominal type case, it was actually wrong because then the resulting interface type does not give the type checker any way to bind the Self type parameter.

There were two existing test cases that now produce errors, which I believe is now correct. While this is technically a source break, because these bogus operators seemingly cannot be witnessed or called, such a protocol probably had no conforming types.

Fixes #73201.

Member operators of concrete nominal types must declare at least
one parameter with that type, like

```
struct S {
  static func +(lhs: S, rhs: Int) -> S {}
}
```

For protocol member operators, we would look for a parameter of type
`Self`, or an existential type `any P`. While the latter was
consistent with the concrete nominal type case, it was actually
wrong because then the resulting interface type does not give the
type checker any way to bind the `Self` type parameter.

There were two existing test cases that now produce errors, which I
believe is now correct. While this is technically a source break,
because these bogus operators seemingly cannot be witnessed or called,
such a protocol probably had no conforming types.

Fixes apple#73201.
@slavapestov
Copy link
Member Author

@swift-ci Please smoke test

@slavapestov slavapestov merged commit 0dd20fd into apple:main Apr 23, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Protocol becomes impossible to implement in this situation
2 participants