Swift compiler crashes on Generic subclasses of NSObject
| Originator: | jiayong.ou | ||
| Number: | rdar://18349699 | Date Originated: | 16-Sep-2014 03:04 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Crash | Reproducible: | Always |
Summary:
When making a generic Swift subclass of `NSObject`, the compiler crashes when the type parameter is not constrained to a class type.
The following code crashes:
```
import Foundation
class Foo<T>: NSObject {
var foo: T
init(foo: T) {
self.foo = foo
super.init()
}
}
```
after adding a constraint that `T` must be `AnyObject`, the crash does not occur:
```
import Foundation
class Foo<T: AnyObject>: NSObject {
var foo: T
init(foo: T) {
self.foo = foo
super.init()
}
}
```
But that would make it impossible to store a value type (e.g. an `Int`) in `foo`…
Steps to Reproduce:
Compile this:
import Foundation
class Foo<T>: NSObject {
var foo: T
init(foo: T) {
self.foo = foo
super.init()
}
}
Expected Results:
Compiler not crashing
Actual Results:
Compiler crashing, see the attached crash log
Version:
Xcode 6 GM, OS X 10.9.4
Notes:
Configuration:
-
Attachments:
'repl_swift_2014-09-16-145441_jaou-rmbp.crash' was successfully uploaded.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!