Swift: using generics, specifying that a types raw value must equal another type allows incorrect raw values

Originator:paulyoungonline
Number:rdar://17970882 Date Originated:10-Aug-2014 01:03 AM
Status:Closed Resolved:Yes
Product:Developer Tools Product Version:Xcode6-beta5 (6A279r)
Classification:Serious Bug Reproducible:Always
 
Summary:
Specifying that a type's raw value must equal another type does not prevent the use of incorrect types.

For example, a function specifying that the raw value of it's generic type must be a string should not allow raw values of any other type.

Steps to Reproduce:
1. Create a playground
2. Define a function that accepts a single argument, whose generic type conforms to RawRepresentable and whose Raw value must equal a String
3. Inside the function body, print the raw value using toRaw()
4. Define an enumerable whose raw value is an Int
5. Inside the enum, provide at least one case
6. Call the function and pass in a case from the enum as the argument

Expected Results:
A compiler error stating that the argument is not of the correct type.

Actual Results:
A runtime exception: Execution was interrupted, reason: EXC_BAD_ACCESS.

Version:
Xcode6-beta5 (6A279r)

Attachments:
SwiftGenericsRawValueBug.playground.zip
SwiftGenericsRawValueBug.png

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!