-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Previous ID | SR-4363 |
Radar | rdar://problem/31275541 |
Original Reporter | vladot (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
Attachment: Download
Environment
Mac OS X 10.11.5 + XCode 8.2.1
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, RunTimeCrash, Runtime |
Assignee | None |
Priority | Medium |
md5: 4be0928a50bcb0c800fb21ca3baf013c
Issue Description:
I am not sure whether this is an NSObject issue or a Swift issue, but since it seems to me that the general problem is with accessing protocol variables after isa-swizzling, I think it falls more in the Swift domain. Here goes:
I have a protocol and the first steps of its type-erasure like so
import Foundation
protocol A: class { }
class AbstractA: A { }
class DelegatedA<D: A>: AbstractA {
init(_ d: D) { }
}
class AnyA: DelegatedA<AbstractA> {
init<D: A>(_ d: D) {
super.init(DelegatedA<D>(d))
}
}
extension A {
var anyA: AnyA {
return AnyA(self)
}
}
Now I declare a class that conforms to the protocol and also inherits from NSObject
class B: NSObject, A { }
Next I declare a variable from the class B and upcast it to NSObject
var b = B()
let d: NSObject = b
Casting d to A and type-erasing it works fine
(d as! A).anyA
Now we define an observer of b
class O: NSObject { }
var o = O()
b.addObserver(o, forKeyPath: "xxx", options: [.new], context: nil)
This isa-swizzles b and now the type-erasure of d crashes
(d as! A).anyA
I have attached a snapshot of the top of the stack after the crash. The crash is in _buildDemanglingForNominalType.
Thanks,
Vladimir