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-8158] Printing type(of: Codable & Protocol type ) EXC_BAD_ACCESS #50690
Comments
Bizarre. Thanks, Stephen. @swift-ci create |
Thanks for the simple and short test case. Worked (crashed) on the first try here. |
Comment by Leandro Barbosa (JIRA) Just to add that I found this post while searching for my own weird issue and it wasn't related to type(of). Any kind of access to the type will cause it. This is a simplified version of what I was trying to do: import Foundation
protocol Proto {
}
typealias CodableProtoObject = NSObject & Codable & Proto
class Foo: CodableProtoObject {
}
class Bar: CodableProtoObject {
}
var codableTypes: [CodableProtoObject.Type] = []
print("we're fine until here...")
codableTypes = [Foo.self, Bar.self]
print("we'll never get here") I tried not using the alias and using the types directly but got the same outcome. Removing Codable or Proto from the typealias is enough to avoid the error. Environment: MacOS 10.13.6 (17G65), XCode 9.4.1 (9F2000) |
Comment by Leandro Barbosa (JIRA) The issue disappears if I restrict the protocol to the classes/protocol in question which is a valid workaround for my use case. This example works: import Foundation
protocol Proto: NSObject & Codable {
}
typealias CodableProtoObject = NSObject & Codable & Proto
class Foo: CodableProtoObject {
}
class Bar: CodableProtoObject {
}
var codableTypes: [CodableProtoObject.Type] = []
print("this is ok...")
codableTypes = [Foo.self, Bar.self]
print("this is fine too!") |
Pull request for the fix: #21119 Turned out to be a really simple incorrect cast. Just a bit hard to track down due to cause and effect being fairly far removed from each other. |
Comment by Stephen (JIRA) I can confirm that in Xcode Version 10.2 (10E125) and Swift version 5.0 (swiftlang-1001.0.69.3 clang-1001.0.47) that the bug has been fixed and the code now performs correctly. |
Comment by Stephen (JIRA)
|
Great, thanks for confirming! |
Comment by Stephen (JIRA) No problem 🙂 |
Closing the issue since the fix has been confirmed. |
Environment
MacOS 10.14 Beta (18A314k), Swift 4.2 included in Xcode Version 10.0 beta 2 (10L177m) and also occurs in Swift 4.1
Additional Detail from JIRA
md5: dfcf32059f3181555b09f3e28f1976d2
Issue Description:
When printing a type of Inheriting class that is stored as a typealias to a composition between any protocol and the Codable protocol, you get a EXC_BAD_ACCESS with the below error in Swift 4.2.
This does not happen if: the class directly inherits from Codable and another protocol, the protocol also inherits from Codable, or the object is not casted to the typealias.
This is a problem and can lead to hard to find bugs in cases where you may store the types and then try to print them later.
The text was updated successfully, but these errors were encountered: