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
swift-ci opened this issue
Mar 15, 2018
· 3 comments
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.CodableArea → standard library: `Codable` and co.compilerThe Swift compiler in itself
SR-7090 Crashing with EXC_BAD_ACCESS after decoding Codable subclass
Issue Description:
When a class inherits from a base class that conforms to Codable, the decoding is not executed (more on that below) and the returned object has the default properties values.
classBaseClass: Codable {}
classMyClass: BaseClass {
enumCodingKeys: String, CodingKey {
caseobjectId = "id" case name } var objectId: Int = -1 var name: String = ""}let dataString = "{\"id\":123,\"name\":\"testobject\"}"
let data = dataString.data(using: .utf8)!
do {
let object = try JSONDecoder().decode(MyClass.self, from: data)
print(object.objectId) //outputs -1 or BAD_ACCESS (and not 123 as expected)
}
catch {
print(error)
}
This is a combination of two issues. The EXC_BAD_ACCESS is indeed SR-7090 & co.; the display of -1 would be caused by MyClassinheritingCodable from BaseClass, since we can't re-synthesize. That issue is being tracked by the now associated Radar; we need to make it clearer that that's what's happening — likely have a warning (with a mechanism to disable) that lets you know what's going on.
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.CodableArea → standard library: `Codable` and co.compilerThe Swift compiler in itself
Attachment: Download
Environment
Version 9.2 (9C40b)
Additional Detail from JIRA
md5: a81e1c99a230bb85f5defb9c13fedb34
relates to:
Issue Description:
When a class inherits from a base class that conforms to Codable, the decoding is not executed (more on that below) and the returned object has the default properties values.
But, if I use either:
The decoding is preformed as expected.
The text was updated successfully, but these errors were encountered: