Skip to content

IRGen: Fix emission of reflection metadata for @objc enums #11341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/IRGen/GenReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,14 @@ void IRGenModule::emitFieldMetadataRecord(const NominalTypeDecl *Decl) {
if (!IRGen.Opts.EnableReflectionMetadata)
return;

// @objc enums never have generic parameters or payloads,
// and lower as their raw type.
if (auto *ED = dyn_cast<EnumDecl>(Decl))
if (ED->isObjC()) {
emitOpaqueTypeMetadataRecord(ED);
return;
}

FieldTypeMetadataBuilder builder(*this, Decl);
builder.emit();
}
Expand Down
10 changes: 10 additions & 0 deletions test/Reflection/Inputs/TypeLoweringObjectiveC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ public class HasObjCClasses {

public class NSObjectSubclass : NSObject {}

@objc public enum ObjCEnum : Int {
case first
case second
}

public struct HasObjCEnum {
let optionalEnum: ObjCEnum?
let reference: AnyObject
}

10 changes: 10 additions & 0 deletions test/Reflection/typeref_lowering_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@
// CHECK: (class TypeLowering.NSObjectSubclass)
// CHECK-NEXT: (reference kind=strong refcounting=unknown)

12TypeLowering11HasObjCEnumV
// CHECK: (struct size=24 alignment=8 stride=24 num_extra_inhabitants=0
// CHECK-NEXT: (field name=optionalEnum offset=0
// CHECK-NEXT: (single_payload_enum size=9 alignment=8 stride=16 num_extra_inhabitants=0
// CHECK-NEXT: (field name=some offset=0
// CHECK-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=0))))
// CHECK-NEXT: (field name=reference offset=16
// CHECK-NEXT: (class_existential size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647
// CHECK-NEXT: (field name=object offset=0
// CHECK-NEXT: (reference kind=strong refcounting=unknown)))))