Swift: Cannot make CGPoint conform to user-defined Protocol
| Originator: | jwight | ||
| Number: | rdar://19509451 | Date Originated: | 1/17/2015 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Serious Boog | Reproducible: | Always and forever |
Summary:
I can make a generic protocol in Swift that has an associated type (see section on Generics in Swift book). I can then make my own types that conform to that protocol:
For example, here's the protocol:
protocol PointType {
typealias ScalarType
var x:ScalarType { get }
var y:ScalarType { get }
}
Here's a struct:
struct IntPoint {
var x:Int
var y:Int
}
And here's where I make the struct conform to the protocol:
extension IntPoint : PointType {
typealias ScalarType = Int
}
Groovy! Unfortunately when I try to make CGPoint conform to the protocol swiftc crashes:
extension CGPoint : PointType {
typealias ScalarType = CGFloat
}
This _should_ work. As far as I should care - CGPoint is just a swift struct (obviously under the hood it is more complex than this)
Steps to Reproduce:
See description.
Expected Results:
Swiftc should not crash and I should be able to make CGPoint confirm to a protocol w/associated types
Actual Results:
Crash!
Version:
Xcode Version 6.2 (6C107a)
Occurs in 6.1.1 too
Notes:
Configuration:
Attachments:
'PointType.swift' was successfully uploaded.
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!
See code in one file at : https://gist.github.com/schwa/78333cadbb599b29c9f7