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-9880] Deprecating default implementation of protocol requirement ineffective #52286

Open
dabrahams opened this issue Feb 7, 2019 · 7 comments
Labels
compiler The Swift compiler in itself improvement

Comments

@dabrahams
Copy link
Collaborator

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

md5: b15e4c5f75b377655237aea63cae8a40

Issue Description:

protocol P {
    func f()
}

extension P {
    @available(*, deprecated, "Please add an explicit implementation of f()")
    func f() {  }
}

struct X : P {  }

The above should produce a diagnostic, e.g. "X's conformance to P uses the default implementation of f, which is deprecated. Please supply an explicit implementation"
but does not.

@theblixguy
Copy link
Collaborator

struct X: P {
func foo() {
 f() // 'f()' is deprecated: Please add an explicit implementation of f()
}
}

When you call `f()`, it does produce the diagnostic. Do you mean we should emit another diagnostic on `X` saying "X's conformance to P uses the default implementation of f(), which is deprecated. Please add an explicit implementation"?

@dabrahams
Copy link
Collaborator Author

Yes, I mean that. It should not produce the diagnostic when you call `f()` from a generic context—it can't tell whether the default implementation has been overridden.

@theblixguy
Copy link
Collaborator

If we do

struct X: P {
  func f() { ... }
  func foo() { f() }
}

then the warning disappears as you've now provided an explicit implementation. I am not fully sure what the benefit is of moving this diagnostic to `X` instead of when you invoke `f` i.e. if you're not using the default implementation at all in `X`, then the warning will persist, which might not be what we want.

@theblixguy
Copy link
Collaborator

If you make it `unavailable, it shows an error diagnostic on X: `Unavailable instance method 'f()' was used to satisfy a requirement of protocol 'P'`

@dabrahams
Copy link
Collaborator Author

"unavailable" breaks clients hard.

The reason for this warning: I am developing a library that vends a protocol and uses its requirements. I published a default implementation. Later I realize that was a mistake and every client should choose her own semantics for the protocol requirement. I want to migrate my users off the default without hard-breaking them.

@theblixguy
Copy link
Collaborator

The users would be notified when you add a deprecation warning to the default implementation i.e. they would see the "Foo is deprecated..." warning in every place in their code where they've been using that default implementation.

However, if you mean a scenario where the users haven't been using it directly and its only your library that uses it and now you want to deprecate it to push users to provide their own implementation, then that makes sense!

@dabrahams
Copy link
Collaborator Author

Yes, users won't have been using this requirement. Often a protocol requirement is there for a framework's consumption in generic contexts, and while users could touch it directly, in practice they don't.

@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