22
33// REQUIRES: swift_in_compiler
44
5- @_used @_section ( " __TEXT,__mysection " ) var g0 : Int = 1
5+ @_used @_section ( " __TEXT,__mysection " ) var g0 : Int = 1 // ok
66
77struct MyStruct {
8- @_used @_section ( " __TEXT,__mysection " ) static var static0 : Int = 1
8+ @_used @_section ( " __TEXT,__mysection " ) static var static0 : Int = 1 // ok
99}
1010
1111struct 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}}
1313
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}}
1515}
1616
1717struct 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}}
1919
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}}
2121}
2222
2323struct 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}}
2626
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+ }
2932}
3033
3134@_section ( " __TEXT,__mysection " ) // expected-error {{'@_section' attribute cannot be applied to this declaration}}
@@ -34,11 +37,30 @@ struct SomeStruct {}
3437@_section ( " " ) var g1 : Int = 1 // expected-error {{@_section section name cannot be empty}}
3538
3639func 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+ }
4060
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+ }
4466}
0 commit comments