3
3
func test_invalid_init_accessor_use( ) {
4
4
var other : String = " " // expected-warning {{}}
5
5
var x : Int {
6
- init ( newValue ) initializes( other) { }
6
+ init ( initialValue ) initializes( other) { }
7
7
// expected-error@-1 {{init accessors could only be associated with properties}}
8
8
9
9
get { 42 }
10
10
}
11
11
12
12
struct X {
13
13
subscript( x: Int ) -> Bool {
14
- init ( newValue ) { } // expected-error {{init accessors could only be associated with properties}}
14
+ init ( initialValue ) { } // expected-error {{init accessors could only be associated with properties}}
15
15
16
16
get { false }
17
17
}
@@ -24,21 +24,21 @@ func test_use_of_initializes_accesses_on_non_inits() {
24
24
var y : String
25
25
26
26
var _x : Int {
27
- init ( newValue ) initializes( x) accesses( y) { // Ok
27
+ init ( initialValue ) initializes( x) accesses( y) { // Ok
28
28
}
29
29
30
30
get { x }
31
31
}
32
32
33
33
var _y : String {
34
34
get { y }
35
- set ( newValue ) initializes( y) { }
35
+ set ( initialValue ) initializes( y) { }
36
36
// expected-error@-1 {{initalizes(...) attribute could only be used with init accessors}}
37
37
}
38
38
39
39
var _q : String {
40
40
get { y }
41
- set ( newValue ) accesses( x) { }
41
+ set ( initialValue ) accesses( x) { }
42
42
// expected-error@-1 {{accesses(...) attribute could only be used with init accessors}}
43
43
}
44
44
}
@@ -48,18 +48,39 @@ func test_invalid_refs_in_init_attrs() {
48
48
struct Test {
49
49
var c : Int { get { 42 } }
50
50
var x : Int {
51
- init ( newValue ) initializes( a) accesses( b c) { }
51
+ init ( initialValue ) initializes( a) accesses( b c) { }
52
52
// expected-error@-1 {{find type 'a' in scope}}
53
53
// expected-error@-2 {{find type 'b' in scope}}
54
54
// expected-error@-3 {{init accessor cannot refer to property 'c'; init accessors can refer only to stored properties}}
55
55
}
56
56
57
57
var y : String {
58
- init ( newValue ) initializes( test) { }
58
+ init ( initialValue ) initializes( test) { }
59
59
// expected-error@-1 {{ambiguous reference to member 'test'}}
60
60
}
61
61
62
62
func test( _: Int ) { } // expected-note {{'test' declared here}}
63
63
func test( _: String ) -> Int { 42 } // expected-note {{'test' declared here}}
64
64
}
65
65
}
66
+
67
+ func test_assignment_to_let_properties( ) {
68
+ struct Test {
69
+ let x : Int
70
+ let y : Int // expected-note {{change 'let' to 'var' to make it mutable}}
71
+
72
+ var pointX : Int {
73
+ init ( initialValue) initializes( x) accesses( y) {
74
+ self . x = initialValue // Ok
75
+ self . y = 42 // expected-error {{cannot assign to property: 'y' is a 'let' constant}}
76
+ }
77
+ }
78
+
79
+ var point : ( Int , Int ) {
80
+ init ( initialValue) initializes( x y) {
81
+ self . x = initialValue. 0 // Ok
82
+ self . y = initialValue. 1 // Ok
83
+ }
84
+ }
85
+ }
86
+ }
0 commit comments