mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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>.
38 lines
1.1 KiB
Objective-C
38 lines
1.1 KiB
Objective-C
#define MY_ERROR_ENUM(_type, _name, _domain) \
|
|
enum _name : _type _name; \
|
|
enum __attribute__((ns_error_domain(_domain))) _name : _type
|
|
|
|
@class NSString;
|
|
|
|
extern NSString * const TagDomain1;
|
|
typedef MY_ERROR_ENUM(int, TagError1, TagDomain1) {
|
|
Badness
|
|
};
|
|
|
|
extern NSString * const TagDomain2;
|
|
typedef MY_ERROR_ENUM(int, TagError2, TagDomain2) {
|
|
Sickness
|
|
};
|
|
|
|
extern NSString * const TypedefDomain1;
|
|
typedef enum __attribute__((ns_error_domain(TypedefDomain1))) {
|
|
Wrongness
|
|
} TypedefError1;
|
|
|
|
extern NSString *TypedefDomain2;
|
|
typedef enum __attribute__((ns_error_domain(TypedefDomain2))) {
|
|
Illness
|
|
} TypedefError2;
|
|
|
|
@interface Nested @end
|
|
|
|
extern NSString * const NestedTagDomain;
|
|
typedef MY_ERROR_ENUM(int, NestedTagError, NestedTagDomain) {
|
|
Trappedness
|
|
} __attribute__((swift_name("Nested.TagError")));
|
|
|
|
extern NSString *NestedTypedefDomain;
|
|
typedef enum __attribute__((ns_error_domain(NestedTypedefDomain))) {
|
|
Brokenness
|
|
} NestedTypedefError __attribute__((swift_name("Nested.TypedefError")));
|