You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-2791 exc_bad_access if I try to inherit generic swift class from NSObject
Issue Description:
A finalized ObjectiveC based generic type with specialized with Swift type will get it work incorrectly. As following code shown,
import UIKit
publicenumUIViewMask{case cornerRadius(CGFloat)case bezierPath(UIBezierPath)case cgPath(CoreGraphics.CGPath)case image(UIImage)case cgImage(CoreGraphics.CGImage)case view(UIView)}publicfinalclassFinalizedObjCAssociated<T>:NSObject{publictypealiasAssociatedValue=Tpublicvarvalue:AssociatedValuepublicinit(_ value:AssociatedValue){self.value = value
super.init()}}publicclassOpenObjCAssociated<T>:NSObject{publictypealiasAssociatedValue=Tpublicvarvalue:AssociatedValuepublicinit(_ value:AssociatedValue){self.value = value
super.init()}}// We create a value with 30 corner radius.letvalue=UIViewMask.cornerRadius(30)// And then create an open associated object,letopenAssociated=OpenObjCAssociated(value)// and a finalized associated object.letfinalizedAssociated=FinalizedObjCAssociated(value)// The open associated object's value is what we just have set.print(openAssociated.value)// But the finalized assocaited object's value is 0.print(finalizedAssociated.value)
we want the `finalizedAssociated.value` to be `.cornerRadius(30)` just like what `openAssociated.value` is, but it will be `.cornerRadius(0)` eventually.
The text was updated successfully, but these errors were encountered:
Yeah, this looks like yet another bug where we mix up generic layout with the ObjC runtime’s sliding. Here’s a minimal test case:
import Foundation
public class C<T>: NSObject {
final public var value: T
public init(_ value: T) {
self.value = value
}
}
let c = C(30)
print(c.value)
The reason it fails specifically when the property is ‘final’ is because we open-code the ref_element_addr there, and we have a concrete type C<Int>. So we use the most specific access pattern we know (constant-direct). But this is wrong because we really ought to use nonconstant-direct. We need to be looking at the original type of the field instead of the substituted type or something.
A workaround is to define a second field of integer type before the final field:
Attachment: Download
Environment
OS X 10.11
iOS 10
Xcode Version 8.0 beta 6 (8S201h)
Additional Detail from JIRA
md5: 97f76b90281c05c56d64e940983d184a
is duplicated by:
Issue Description:
A finalized ObjectiveC based generic type with specialized with Swift type will get it work incorrectly. As following code shown,
we want the `finalizedAssociated.value` to be `.cornerRadius(30)` just like what `openAssociated.value` is, but it will be `.cornerRadius(0)` eventually.
The text was updated successfully, but these errors were encountered: