Skip to content

Commit 8c95738

Browse files
committed
Add test case
1 parent f33077a commit 8c95738

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/Unsafe/safe.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature AllowUnsafeAttribute -enable-experimental-feature WarnUnsafe -print-diagnostic-groups
2+
3+
// REQUIRES: swift_feature_AllowUnsafeAttribute
4+
// REQUIRES: swift_feature_WarnUnsafe
5+
6+
@unsafe
7+
func unsafeFunction() { }
8+
9+
@unsafe
10+
struct UnsafeType { } // expected-note{{unsafe struct 'UnsafeType' declared here}}
11+
12+
@safe(unchecked)
13+
func f() {
14+
unsafeFunction()
15+
}
16+
17+
@safe(unchecked, message: "I was careful")
18+
func g() {
19+
unsafeFunction()
20+
}
21+
22+
// expected-note@+2{{mark the enclosing global function 'h' '@unsafe' to allow it to use unsafe constructs}}
23+
@safe(unchecked, message: "I was careful")
24+
func h(_: UnsafeType) { // expected-warning{{reference to unsafe struct 'UnsafeType' [Unsafe]}}
25+
unsafeFunction()
26+
}
27+
28+
// Parsing issues
29+
@safe // expected-error{{expected '(' in 'safe' attribute}}
30+
func bad1() { }
31+
32+
@safe() // expected-error{{'@safe' attribute must be written as '@safe(unchecked)'}}
33+
func bad2() { }
34+
35+
@safe(blah) // expected-error{{'@safe' attribute must be written as '@safe(unchecked)'}}
36+
func bad3() { }
37+
38+
@safe(5) // expected-error{{'@safe' attribute must be written as '@safe(unchecked)'}}
39+
func bad4() { }
40+
41+
@safe(unchecked, blah) // expected-error{{unknown option 'blah' for attribute 'safe'}}
42+
func bad5() { }
43+
44+
@safe(unchecked, message) // expected-error{{expected ':' after label 'message'}}
45+
func bad6() { }
46+
47+
@safe(unchecked, message: "a\(b)") // expected-error{{message cannot be an interpolated string literal}}
48+
func bad7() { }

0 commit comments

Comments
 (0)