Skip to content

Commit 4522963

Browse files
committed
Serialization: Handle enum cases in ExternallyAccessibleDeclVisitor.
1 parent ee479fe commit 4522963

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3416,9 +3416,20 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
34163416
UNREACHABLE(IfConfig);
34173417
UNREACHABLE(PrecedenceGroup);
34183418
UNREACHABLE(Operator);
3419-
UNREACHABLE(EnumCase);
34203419

34213420
#undef UNREACHABLE
3421+
3422+
// Uninteresting decls are always considered external. A kind of decl might
3423+
// always be external if it is declared at the top level and access control
3424+
// does not apply to it. Or, a kind of decl could be considered always
3425+
// external because it is only found nested within other declarations that
3426+
// have their own access level, in which case we assume that the declaration
3427+
// context has already been checked.
3428+
#define UNINTERESTING(KIND) \
3429+
bool visit##KIND##Decl(const KIND##Decl *D) { return true; }
3430+
UNINTERESTING(EnumCase);
3431+
3432+
#undef UNINTERESTING
34223433
};
34233434

34243435
public:

test/Inputs/lazy_typecheck.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,26 @@ class InternalClass: DoesNotExist { // expected-error {{cannot find type 'DoesNo
168168
init(x: DoesNotExist) {} // expected-error {{cannot find type 'DoesNotExist' in scope}}
169169
}
170170

171+
public enum PublicEnum {
172+
case a
173+
case b(x: Int)
174+
175+
public func publicMethod() -> Int {
176+
return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
177+
}
178+
179+
public var publicComputedVar: Int {
180+
return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
181+
}
182+
}
183+
184+
enum InternalEnum {
185+
case bad(DoesNotExist) // expected-error {{cannot find type 'DoesNotExist' in scope}}
186+
187+
func method() -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
188+
}
189+
}
190+
171191
// MARK: - Conformances
172192

173193
public struct PublicStructConformingToPublicProto: PublicProto {
@@ -222,4 +242,3 @@ extension PublicGenericStruct where T == InternalStructForConstraint {}
222242

223243
extension PublicGenericStruct: EmptyPublicProto where T == InternalStructForConstraint {}
224244

225-
// FIXME: Test enums

test/Inputs/lazy_typecheck_client.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ func testPublicClass() {
5050
PublicDerivedClass.publicClassMethod()
5151
}
5252

53+
func testPublicEnum(_ e: PublicEnum) {
54+
switch e {
55+
case .a: ()
56+
case .b(let x): let _: Int = x
57+
}
58+
59+
let _: Int = e.publicMethod()
60+
let _: Int = e.publicComputedVar
61+
}
62+
5363
func testConformances() {
5464
let array: [any PublicProto] = [
5565
PublicStructConformingToPublicProto(),

test/ModuleInterface/lazy-typecheck.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@
6969
// CHECK: override public init(x: Swift.Int)
7070
// CHECK: deinit
7171
// CHECK: }
72+
// CHECK: public enum PublicEnum {
73+
// CHECK: case a
74+
// CHECK: case b(x: Swift.Int)
75+
// CHECK: public func publicMethod() -> Swift.Int
76+
// CHECK: public var publicComputedVar: Swift.Int {
77+
// CHECK-NEXT: get
78+
// CHECK-NEXT: }
79+
// CHECK: }
7280
// CHECK: public struct PublicStructConformingToPublicProto : lazy_typecheck.PublicProto {
7381
// CHECK: public init()
7482
// CHECK: public func req() -> Swift.Int

test/TBD/lazy-typecheck.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ exports:
5656
'_$s14lazy_typecheck034PublicStructIndirectlyConformingToC5ProtoVMa',
5757
'_$s14lazy_typecheck034PublicStructIndirectlyConformingToC5ProtoVMn',
5858
'_$s14lazy_typecheck034PublicStructIndirectlyConformingToC5ProtoVN',
59-
'_$s14lazy_typecheck10publicFuncSiyF', '_$s14lazy_typecheck11PublicClassC06publicD6MethodyyFZTj',
59+
'_$s14lazy_typecheck10PublicEnumO12publicMethodSiyF', '_$s14lazy_typecheck10PublicEnumO17publicComputedVarSivg',
60+
'_$s14lazy_typecheck10PublicEnumO17publicComputedVarSivpMV',
61+
'_$s14lazy_typecheck10PublicEnumO1ayA2CmFWC', '_$s14lazy_typecheck10PublicEnumO1byACSi_tcACmFWC',
62+
'_$s14lazy_typecheck10PublicEnumOMa', '_$s14lazy_typecheck10PublicEnumOMn',
63+
'_$s14lazy_typecheck10PublicEnumON', '_$s14lazy_typecheck10publicFuncSiyF',
64+
'_$s14lazy_typecheck11PublicClassC06publicD6MethodyyFZTj',
6065
'_$s14lazy_typecheck11PublicClassC06publicD6MethodyyFZTq',
6166
'_$s14lazy_typecheck11PublicClassC12publicMethodSiyFTj', '_$s14lazy_typecheck11PublicClassC12publicMethodSiyFTq',
6267
'_$s14lazy_typecheck11PublicClassC14publicPropertySivMTj',

0 commit comments

Comments
 (0)