Protocol as type (accessed from dynamicType) causes a segmentation fault
| Originator: | lukeben92 | ||
| Number: | rdar://17359448 | Date Originated: | 18-Jun-2014 08:33 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6 Beta 2 |
| Classification: | Swift | Reproducible: | Always |
Summary:
When an object has a protocol type, attempting to use a class method of its dynamicType causes a segmentation fault. In the playground, Xcode crashes, and in the project, Xcode won't compile.
Sample code:
protocol MyProtocol
{
class func test() -> String
}
class MyClass: MyProtocol
{
class func test() -> String
{
return "MyClass test"
}
}
var protocolInstance: MyProtocol = MyClass()
protocolInstance.dynamicType.test() // crashes
Steps to Reproduce:
1. Install Xcode
2. Open a new playground
3. Paste the sample code from the description
Expected Results:
The appropriate class method of the dynamicType should be called.
Actual Results:
Xcode crashes when in a playground or will not compile when in a project due to a segmentation fault.
Version:
Xcode 6 Beta 2, OS X Mavericks
(Also occurs in Xcode 6 Beta 1)
Notes:
One (sloppy) workaround is to duplicate the class method as an instance method. The sample code above would look like this:
protocol MyProtocol
{
class func test() -> String
func test() -> String
}
class MyClass: MyProtocol
{
class func test() -> String
{
return "MyClass test"
}
func test() -> String
{
return MyClass.test()
}
}
var protocolInstance: MyProtocol = MyClass()
protocolInstance.test() // works fine
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!