swift icon indicating copy to clipboard operation
swift copied to clipboard

[SR-2078] Conformance to an @objc protocol by a generic type in an extension crashes the compiler

Open jadengeller opened this issue 10 years ago • 4 comments

Previous ID SR-2078
Radar rdar://problem/21216149
Original Reporter @jadengeller
Type Bug

Environment

Swift 2.2 and Swift 3 b2; other versions untested, but presumably fail also

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

md5: 11c43ab459a5ddfe3d39d960cac1fdd2

is duplicated by:

  • SR-4130 Extensions of generic subclasses of NSObject defined in Swift crash in IRGen

Issue Description:

The following will crash the Swift compiler.

@objc protocol Fooable {}
class Foo<T> {}
extension Foo: Fooable {}

jadengeller avatar Jul 14 '16 20:07 jadengeller

I believe this bug may be related to SR-2146.

The following will crash the compiler.

@objc protocol Fooable {}
protocol Barable: Foible {}
class Foo<T> {}
extension Foo: Barable {}

The following modification, where a redundant conformance to `Fooable` is stated at the declaration of `Foo`, serves as a workaround.

@objc protocol Fooable {}
protocol Barable: Fooable {}
class Foo<T>: Fooable {}
extension Foo: Barable {}

jadengeller avatar Jul 22 '16 19:07 jadengeller

Wrong related bug number?

The problem is that generic types can't get Objective-C categories at the moment, which means extensions can't add protocols or @objc members. These should definitely have proper errors, though.

belkadan avatar Jul 25 '16 17:07 belkadan

Oh good catch. I meant SR-2146, though I'm not sure that it's related anymore.

jadengeller avatar Jul 25 '16 18:07 jadengeller

I believe this has been resolved, as the given code produces an error in the Xcode 10 toolchain.
@objc protocol Fooable {}class Foo<T> {}
extension Foo: Fooable {} // Conformance of generic class 'Foo<T>' to @objc protocol 'Fooable' cannot be in an extension

Dante-Broggi avatar Sep 30 '18 20:09 Dante-Broggi