-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathsafe_argument_suppression.swift
50 lines (36 loc) · 1.14 KB
/
safe_argument_suppression.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// RUN: %target-typecheck-verify-swift -strict-memory-safety -print-diagnostic-groups
@unsafe
class NotSafe {
@safe var okay: Int { 0 }
@safe var safeSelf: NotSafe { unsafe self }
@safe func memberFunc(_: NotSafe) { }
@safe subscript(ns: NotSafe) -> Int { 5 }
@safe static func doStatically(_: NotSafe.Type) { }
@safe static subscript(ns: NotSafe) -> Int { 5 }
@safe init(_: NotSafe) { }
func stillUnsafe() { }
}
@unsafe
class NotSafeSubclass: NotSafe {
}
@safe func okayFunc(_ ns: NotSafe) { }
@safe func testImpliedSafety(ns: NotSafe) {
_ = ns.okay
_ = ns.safeSelf.okay
ns.memberFunc(ns)
okayFunc(ns)
_ = ns[ns]
_ = NotSafe(ns)
_ = NotSafe[ns]
NotSafe.doStatically(NotSafe.self)
ns.stillUnsafe() // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe' [StrictMemorySafety]}}
// expected-note@-1{{reference to parameter 'ns' involves unsafe type 'NotSafe'}}
// expected-note@-2{{reference to unsafe instance method 'stillUnsafe()'}}
}
@safe func testImpliedSafetySubclass(ns: NotSafeSubclass) {
_ = ns.okay
_ = ns.safeSelf.okay
ns.memberFunc(ns)
okayFunc(ns)
_ = ns[ns]
}