-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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-815] Generic classes with default property initializers bug #43427
Comments
Sorry, what's crashing? Can you include the code that constructs one of these things and calls |
Comment by Victor Shamanov (JIRA) @belkadan Just create an instance of |
Comment by Miroslav Kuzmisin (JIRA) same problem here, please note that this bug has to be prioritized as urgent/critical, because app for ios7 cannot be published problem comes with latest Xcode(7.3 - 7D175)/swift
you have to run it on real device with ios7 (ios8, ios9 work without problem), this bug is 100% reproducible, just run this code class SomeClass<T> {
var anything: Int?
// var generic: T? // crash with or without
}
let test = SomeClass<String>() // EXC_BAD_ACCES please let us know, if you can reproduce it, or you will need another steps from us, many thanks ... |
Comment by Victor Shamanov (JIRA) kuzmisin (JIRA User) Please notice, that you can work around it just by changing declaration order of your properties. class SomeClass<T> {
var generic: T?
var anything: Int?
}
let test = SomeClass<String>() |
Comment by Miroslav Kuzmisin (JIRA) Victor thanks ... hmm, for simple case, like class SomeClass<T> {
var generic: T?
var dummy: Int?
} works, but for real example, still crashing class SomeClass<T> {
var generic: [Int: T]?
var dummy: Int?
} |
Comment by Victor Shamanov (JIRA) kuzmisin (JIRA User) Did you try to initialize those properties in initializer? class SomeClass<T> {
var generic: [Int: T]?
var dummy: Int?
init() {
generic = nil
dummy = nil
}
} |
Comment by Miroslav Kuzmisin (JIRA) yes, and also with generic = [Int: T]()
dummy = 1 still crashing (note: I am testing it on clear iOS project to avoid any 3rd party problems) |
Comment by Victor Shamanov (JIRA) kuzmisin (JIRA User) maybe this would work: class SomeClass<T> {
private var _generic: Any?
var generic: [Int: T]? {
get {
return _generic as! [Int: T]?
}
set {
_generic = newValue
}
}
var dummy: Int?
} |
Comment by Miroslav Kuzmisin (JIRA) wiruzx (JIRA User) nope, still crashing ... maybe another user with same problem http://stackoverflow.com/questions/36201272/tests-with-generic-classes-crash-since-swift-2-2 |
Comment by Daniel Klöck (JIRA) I seem to have the same problem, but I'm using swift 2.2 and it also happens on a device with Version 9.3 (13E233) and on the simulator (also with 9.3, I haven't tested older versions). Is there any other solution yet? Half of my classes are affected. This should be high prio. In my case, the problem began with swift 2.2, before that update everything was working fine. |
Comment by Daniel Klöck (JIRA) This guy also seems to be having the same issue: http://stackoverflow.com/questions/36235369/xcode-7-3-generics |
Comment by Daniel Klöck (JIRA) I corrected my problem by initializing all object in `init` as the description suggested |
Comment by WenLong Meng (JIRA) Environment: swift 2.2 class Object1 {
init () {
let object2 = Object2(self)
}
}
class Object2<T: AnyObject> {
weak var object: T?
init(_ object: T) {
self.object = object
}
}
|
Victor, didn't you say your original problem appeared with 2.1 as well? That's how I interpreted your "Environment" entry. |
Comment by Victor Shamanov (JIRA) @belkadan Couldn't tell if it was in 2.1, but it surely was in 2.1.1 |
Okay, then it sounds like Daniel and Miroslav are hitting a different issue. (It could certainly be the same underlying issue, but I don't think we can assume that.) Maybe we should track that with a different bug, and link them? |
Comment by Victor Shamanov (JIRA) Make sense. |
Comment by Miroslav Kuzmisin (JIRA) wiruzx (JIRA User) ok, no problem, I've created BUG [SR-1201] |
Comment by Miroslav Kuzmisin (JIRA) looks like fixed in (today updated) XCODE Version 7.3.1 (7D1014), in short test everything is working - no crash |
I also confirm that looks like fixed in xcode 7.3.1 |
Comment by Egor (JIRA) Still not working for subclasses of generic classes with attributes class GenericClass<T> {
let attribute = 0
}
class GenericSubclass: GenericClass<Int> {
var otherAttribute: Int { return 0 }
}
let _ = GenericSubclass() class GenericClass<T> {
let attribute = 0
}
class GenericSubclass: GenericClass<Int> {
let otherAttribute = 0
}
let _ = GenericSubclass() class GenericClass<T> {
var value: T?
let attribute = 0
}
class GenericSubclass: GenericClass<Int> {
let otherAttribute = 0
}
let _ = GenericSubclass() |
Egor, what version of XCode are you using? |
Comment by Egor (JIRA) Slava, XCode 7.1.3, device - iPhone 4, iOS 7.1.2 |
Comment by Ryan (JIRA) Hi, It would be greatly appreciated if this bug were resolved as it makes Swift and iOS7 a almost no-go. Thank you for your consideration! 🙂 A work-around was discovered though that would at least let us support iOS7 without a significant rewrite. Example: // This heavily pollutes the codebase, so let's keep track of it but using a common meaningless generic value so we can find and destroy later when we no longer support iOS7
protocol iOS7SwiftGenericFixProtocol {}
struct iOS7SwiftGenericFixType: iOS7SwiftGenericFixProtocol {}
class GenericClass<T> {
var value: T?
let attribute = 0
}
class GenericSubclass<Element: iOS7SwiftGenericFixProtocol>: GenericClass<Int> {
let otherAttribute = 0
}
let _ = GenericSubclass<iOS7SwiftGenericFixType>() |
Unfortunately, iOS 7 appears to be out of reach for the latest Swift release. You are welcome to reopen the issue if it happens to reemerge on a less distant deployment target. |
Environment
Swift 2.1.1, iOS 7
Swift 2.2, iOS 9.3
Additional Detail from JIRA
md5: ab6cd5d5f6905bbd52b11768623b6abf
is duplicated by:
relates to:
Issue Description:
It doesn't matter if object will be NSObject or Swift's ref type.
Bug is not being reproduced if you either:
make class non-generic,
remove `value` property,
swap `object` and `value` properties declarations,
initialize object in `init`
This issue reproduces only on iOS 7
The text was updated successfully, but these errors were encountered: