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-4184] Swift 3.1: Overriding a generic method with a generic class fails #46767

Closed
swift-ci opened this issue Mar 7, 2017 · 3 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Mar 7, 2017

Previous ID SR-4184
Radar rdar://problem/30880621
Original Reporter davidp_navdy (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Environment

Xcode: Version 8.2.1 (8C1002)
macOS: 10.12.3 (16D32)

For Swift 3.1, used the 3.1 Snapshot dated March 6, 2017.

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

md5: 85f3df58b7d60e6325cc8770beef7e52

Issue Description:

The following code compiles using Swift 3.0.2/Xcode 8.2; it reports an error using Xcode 8.3 beta 3 and the latest Swift 3.1 snapshot:

import Foundation

class Foo {
    func add<T: Equatable>(_ thing: T) {}
}

class Bar<T: Equatable>: Foo {
    override func add(_ thing: T) {}
}

Before and after:

$ xcrun swiftc --version
Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9
$ xcrun swiftc Contents.swift # no error
$ xcrun --toolchain swift swiftc --version
Apple Swift version 3.1-dev (LLVM a7c680da51, Clang 9772bf511a, Swift 493db43364)
Target: x86_64-apple-macosx10.9
$ xcrun --toolchain swift swiftc Contents.swift 
Contents.swift:10:19: error: method does not override any method from its superclass
    override func add(_ thing: T) {}
    ~~~~~~~~      ^

If I change the definition of Bar to:

class Bar: Foo {
    override func add<T: Equatable>(_ thing: T) {}
}

... then it builds with both versions of Swift.

I've also filed in radar as 30880621.

@belkadan
Copy link
Contributor

belkadan commented Mar 7, 2017

@slavapestov points out that the code isn't actually correct; if Bar's version was a true override, I would be able to do Bar<Int>().add("abc"), since I can do Foo().add("abc").

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 7, 2017

Comment by David Paschich (JIRA)

I think you're probably right, that accepting the code as written was probably a bug. I'll leave it to y'all to decide whether to be backwards compatible with bad code. 🙂

@swift-ci
Copy link
Collaborator Author

Comment by David Paschich (JIRA)

It seems the radar has been closed as "Behaves correctly". Will this issue see the same fate?

@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
Projects
None yet
Development

No branches or pull requests

2 participants