Skip to content

Commit 88d796b

Browse files
committed
[Serialization] Test looking through all possible members of AnyObject
Loading all possible members for the static type AnyObject can trigger deserialization of members of non-public types. Deserialization safety should prevent this by refusing to load the members themselves and even avoid accessing their context.
1 parent 2dff001 commit 88d796b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// REQUIRES: asserts
5+
// REQUIRES: VENDOR=apple
6+
7+
/// Build library.
8+
// RUN: %target-swift-frontend -emit-module %t/Lib.swift \
9+
// RUN: -enable-library-evolution -swift-version 5 \
10+
// RUN: -emit-module-path %t/Lib.swiftmodule
11+
12+
/// Build client.
13+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
14+
// RUN: -verify -Xllvm -debug-only=Serialization \
15+
// RUN: -enable-deserialization-safety 2>&1 \
16+
// RUN: | %FileCheck --check-prefixes=SAFE %s
17+
18+
/// Decls skips by the deserialization safety logic.
19+
// SAFE-NOT: InternalClass
20+
// SAFE: Deserialized: 'PublicClass'
21+
// SAFE: Deserialized: 'publicFunc()'
22+
// SAFE: Skipping unsafe deserialization: 'privateFunc()'
23+
// SAFE: Skipping unsafe deserialization: 'fileprivateFunc()'
24+
// SAFE: Skipping unsafe deserialization: 'internalFunc()'
25+
26+
//--- Lib.swift
27+
28+
import Foundation
29+
30+
@objc
31+
public class PublicClass : NSObject {
32+
public func publicFunc() {}
33+
}
34+
35+
@objc
36+
internal class InternalClass : NSObject {
37+
private func privateFunc() {}
38+
fileprivate func fileprivateFunc() {}
39+
internal func internalFunc() {}
40+
}
41+
42+
//--- Client.swift
43+
44+
import Lib
45+
46+
var x: AnyObject
47+
48+
// Trigger a typo correction to read all members of all subtypes to NSObject.
49+
x.notAMember() // expected-error {{value of type 'AnyObject' has no member 'notAMember'}}

0 commit comments

Comments
 (0)