Files
swift-mirror/test/Inputs/custom-modules/ErrorEnums.h
Brent Royal-Gordon affcefc1ae [ASTMangler] Mangle nested imported error structs correctly
Error structs synthesized by ClangImporter can be renamed using SWIFT_NAME() to syntactically appear anywhere in the type hierarchy with any name, but they should always be mangled as `__C_Synthesized.related decl ‘e’ of <Objective-C enum name>`. Unforunately, when SWIFT_NAME() was used to nest the error struct inside another type, an ASTMangler bug would cause it to be mangled as `<parent type>.related decl ‘e’ of <Objective-C enum name>`, and an ASTDemangler bug would also require a valid parent type. This created a mismatch between the compiler’s and runtime’s manglings which caused crashes when you tried to match the imported error struct in a `catch`.

This PR corrects the compiler bugs so that it generates the mangling the runtime expects. This is theoretically ABI-breaking, but as far as I can determine nobody has shipped the incorrectly mangled names, presumably because they crash when you try to use them.

Fixes <rdar://problem/48040880>.
2019-05-15 11:28:24 -07:00

34 lines
914 B
C

@import Foundation;
NSString * const MyErrorDomain;
typedef NS_ENUM(int, MyError) {
MyErrorGood,
MyErrorBad,
} __attribute__((ns_error_domain(MyErrorDomain)));
NSString * const MyRenamedErrorDomain;
typedef NS_ENUM(int, MyRenamedError) {
MyRenamedErrorGood,
MyRenamedErrorBad,
} __attribute__((ns_error_domain(MyRenamedErrorDomain))) __attribute__((swift_name("RenamedError")));
struct Wrapper {
int unrelatedValue;
};
NSString * const MyMemberErrorDomain;
typedef NS_ENUM(int, MyMemberError) {
MyMemberErrorA,
MyMemberErrorB,
} __attribute__((ns_error_domain(MyMemberErrorDomain))) __attribute__((swift_name("Wrapper.MemberError")));
// Not actually an error enum, but it can still hang with us.
typedef NS_ENUM(int, MyMemberEnum) {
MyMemberEnumA,
MyMemberEnumB,
} __attribute__((swift_name("Wrapper.MemberEnum")));
typedef int WrapperByAttribute __attribute__((swift_wrapper(struct)));