2
2
3
3
// REQUIRES: swift_in_compiler
4
4
5
- @_used @_section ( " __TEXT,__mysection " ) var g0 : Int = 1
5
+ @_used @_section ( " __TEXT,__mysection " ) var g0 : Int = 1 // ok
6
6
7
7
struct MyStruct {
8
- @_used @_section ( " __TEXT,__mysection " ) static var static0 : Int = 1
8
+ @_used @_section ( " __TEXT,__mysection " ) static var static0 : Int = 1 // ok
9
9
}
10
10
11
11
struct MyStruct2 {
12
- @_section ( " __TEXT,__mysection " ) var member0 : Int = 1 // expected-error {{properties with attribute '_section' must be static}}
12
+ @_section ( " __TEXT,__mysection " ) var member0 : Int = 1 // expected-error {{properties with attribute '_section' must be static}}
13
13
14
- @_section ( " __TEXT,__mysection " ) static var member0 : Int { return 1 } // expected-error {{'@_section' must not be used on computed properties}}
14
+ @_section ( " __TEXT,__mysection " ) static var static1 : Int { return 1 } // expected-error {{'@_section' must not be used on computed properties}}
15
15
}
16
16
17
17
struct MyStruct3 < T> {
18
- static var member0 : Int = 1 // expected-error {{static stored properties not supported in generic types}}
18
+ static var member1 : Int = 1 // expected-error {{static stored properties not supported in generic types}}
19
19
20
- @_section ( " __TEXT,__mysection " ) func foo( ) { } // expected-error {{attribute '_section' cannot be used in a generic context}}
20
+ @_section ( " __TEXT,__mysection " ) func foo( ) { } // expected-error {{attribute '_section' cannot be used in a generic context}}
21
21
}
22
22
23
23
struct MyStruct4 < T> {
24
- struct InnerStruct {
25
- static var member0 : Int = 1 // expected-error {{static stored properties not supported in generic types}}
24
+ struct InnerStruct {
25
+ static var member2 : Int = 1 // expected-error {{static stored properties not supported in generic types}}
26
26
27
- @_section ( " __TEXT,__mysection " ) func foo( ) { } // expected-error {{attribute '_section' cannot be used in a generic context}}
28
- }
27
+ @_section ( " __TEXT,__mysection " ) static var member3 : Int = 1 // expected-error {{static stored properties not supported in generic types}}
28
+ // expected-error@-1 {{attribute '_section' cannot be used in a generic context}}
29
+
30
+ @_section ( " __TEXT,__mysection " ) func foo( ) { } // expected-error {{attribute '_section' cannot be used in a generic context}}
31
+ }
29
32
}
30
33
31
34
@_section ( " __TEXT,__mysection " ) // expected-error {{'@_section' attribute cannot be applied to this declaration}}
@@ -34,11 +37,30 @@ struct SomeStruct {}
34
37
@_section ( " " ) var g1 : Int = 1 // expected-error {{@_section section name cannot be empty}}
35
38
36
39
func function( ) {
37
- @_section ( " __TEXT,__mysection " ) var l0 : Int = 1 // expected-error {{attribute '_section' can only be used in a non-local scope}}
38
- l0 += 1
39
- _ = l0
40
+ @_section ( " __TEXT,__mysection " ) var l0 : Int = 1 // expected-error {{attribute '_section' can only be used in a non-local scope}}
41
+ l0 += 1
42
+ _ = l0
43
+
44
+ @_used var l1 : Int = 1 // expected-error {{attribute '_used' can only be used in a non-local scope}}
45
+ l1 += 1
46
+ _ = l1
47
+ }
48
+
49
+ func function_with_type( ) {
50
+ class MyClass {
51
+ @_section ( " __TEXT,__mysection " ) static var member : Int = 1 // ok
52
+ }
53
+
54
+ do {
55
+ class MyClass {
56
+ @_section ( " __TEXT,__mysection " ) static var member : Int = 1 // ok
57
+ }
58
+ }
59
+ }
40
60
41
- @_used var l1 : Int = 1 // expected-error {{attribute '_used' can only be used in a non-local scope}}
42
- l1 += 1
43
- _ = l1
61
+ func function_with_type_generic< T> ( ) -> T {
62
+ class MyClass { // expected-error {{type 'MyClass' cannot be nested in generic function}}
63
+ @_section ( " __TEXT,__mysection " ) static var member : Int = 1 // expected-error {{static stored properties not supported in generic types}}
64
+ // expected-error@-1 {{attribute '_section' cannot be used in a generic context}}
65
+ }
44
66
}
0 commit comments