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-11041] Generic Extension numeric protocol #53430

Closed
swift-ci opened this issue Jun 28, 2019 · 1 comment
Closed

[SR-11041] Generic Extension numeric protocol #53430

swift-ci opened this issue Jun 28, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11041
Radar None
Original Reporter prashantkt (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee None
Priority Medium

md5: 8b65a80ad9449b324d2e7a14bfad7132

Issue Description:

extension Numeric {
  func percentage<T>(of: T) -> T where T.Type == Self.Type {
    return self / of
  }
}

But I get the error

Same-type requirement makes generic parameters 'T' and 'Self' equivalent

However this is working fine

extension Numeric {
    func percentage<Self>(of whole: Self) -> Self {
        return self / whole
    }
} 

I don't see any reason why it shouldn't be allowed ?

@belkadan
Copy link
Contributor

That's pretty much what the error message is trying to tell you: you've gained no benefit from using T; just use Self instead. Maybe the compiler can say that more clearly, though. (If it's really smart, it could try to do the replacement for you, but I'm not sure we want to go that far.)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

No branches or pull requests

2 participants