Commits

Jordan Rose committed 83639ca7027
[ClangImporter] Add convert-inits for enums defined in terms of other enums. This pattern isn't too uncommon: typedef CF_ENUM(CFIndex, CFFoo) { CFFooBar }; typedef NS_ENUM(NSInteger, NSFoo) { NSFooBar = CFFooBar }; NSFoo and CFFoo are distinct types, but sometimes you need to convert from one to the other. Today the only way to do to that is via rawValue, which is especially unpleasant if the raw types don't match. This commit introduces a new converting initializer for NSFoo: init!(_ value: CFFoo) { self.init(rawValue: RawType(value.rawValue)) } It's failable by necessity because init(rawValue:) is failable for proper enums. In practice an audit of our public headers found zero cases where there are "more" cases in CFFoo than in NSFoo, i.e. cases where the conversion would fail. This also applies to option sets and opaque enums, but those use a non-failable initializer because there's no way to check validity. rdar://problem/19667625 Swift SVN r25401