Skip to content

Commit 492a26b

Browse files
committed
[SwiftRemoteMirror] Consider ObjCClass field descriptors when converting TypeInfos
@slava_pestov recently folded in @objc classes when building class field descriptors - we just need to update the switch when considering records for converting TypeRefs to TypeInfos. rdar://problem/26594130
1 parent 3753d77 commit 492a26b

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

stdlib/public/Reflection/TypeLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,8 @@ const TypeInfo *TypeConverter::getClassInstanceTypeInfo(const TypeRef *TR,
10131013
return nullptr;
10141014

10151015
switch (FD->Kind) {
1016-
case FieldDescriptorKind::Class: {
1016+
case FieldDescriptorKind::Class:
1017+
case FieldDescriptorKind::ObjCClass: {
10171018
// Lower the class's fields using substitutions from the
10181019
// TypeRef to make field types concrete.
10191020
RecordTypeInfoBuilder builder(*this, RecordKind::ClassInstance);
@@ -1030,7 +1031,6 @@ const TypeInfo *TypeConverter::getClassInstanceTypeInfo(const TypeRef *TR,
10301031
case FieldDescriptorKind::ObjCProtocol:
10311032
case FieldDescriptorKind::ClassProtocol:
10321033
case FieldDescriptorKind::Protocol:
1033-
case FieldDescriptorKind::ObjCClass:
10341034
// Invalid field descriptor.
10351035
return nullptr;
10361036
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: %target-build-swift -lswiftSwiftReflectionTest %s -o %t/inherits_NSObject
3+
// RUN: %target-run %target-swift-reflection-test %t/inherits_NSObject | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
4+
5+
import Foundation
6+
7+
import SwiftReflectionTest
8+
9+
class InheritsNSObject : NSObject {}
10+
class ContainsInheritsNSObject : NSObject {
11+
var a: InheritsNSObject
12+
var _b: InheritsNSObject
13+
14+
var b: InheritsNSObject {
15+
get { return _b }
16+
set (newVal) { _b = newVal }
17+
}
18+
19+
override init() {
20+
a = InheritsNSObject()
21+
_b = InheritsNSObject()
22+
}
23+
}
24+
25+
let inheritsNSObject = InheritsNSObject()
26+
reflect(object: inheritsNSObject)
27+
28+
// CHECK-64: Reflecting an object.
29+
// CHECK-64: Type reference:
30+
// CHECK-64: (class inherits_NSObject.InheritsNSObject)
31+
32+
// CHECK-64: Type info:
33+
// CHECK-64: (class_instance size=8 alignment=16 stride=16 num_extra_inhabitants=0)
34+
35+
// CHECK-32: Reflecting an object.
36+
// CHECK-32: Type reference:
37+
// CHECK-32: (class inherits_NSObject.InheritsNSObject)
38+
39+
// CHECK-32: Type info:
40+
// CHECK-32: (class_instance size=4 alignment=8 stride=8 num_extra_inhabitants=0)
41+
42+
let sc = ContainsInheritsNSObject()
43+
reflect(object: sc)
44+
45+
// CHECK-64: Reflecting an object.
46+
// CHECK-64: Type reference:
47+
// CHECK-64: (class inherits_NSObject.ContainsInheritsNSObject)
48+
49+
// CHECK-64: Type info:
50+
// CHECK-64: (class_instance size=24 alignment=16 stride=32 num_extra_inhabitants=0
51+
// CHECK-64-NEXT: (field name=a offset=8
52+
// CHECK-64-NEXT: (reference kind=strong refcounting=unknown))
53+
// CHECK-64-NEXT: (field name=_b offset=16
54+
// CHECK-64-NEXT: (reference kind=strong refcounting=unknown)))
55+
56+
// CHECK-32: Reflecting an object.
57+
// CHECK-32: Type reference:
58+
// CHECK-32: (class inherits_NSObject.ContainsInheritsNSObject)
59+
60+
// CHECK-32: Type info:
61+
// CHECK-32: (class_instance size=12 alignment=8 stride=16 num_extra_inhabitants=0
62+
// CHECK-32-NEXT: (field name=a offset=4
63+
// CHECK-32-NEXT: (reference kind=strong refcounting=unknown))
64+
// CHECK-32-NEXT: (field name=_b offset=8
65+
// CHECK-32-NEXT: (reference kind=strong refcounting=unknown)))
66+
67+
doneReflecting()

0 commit comments

Comments
 (0)