@@ -58,6 +58,63 @@ Swift 5.2
58
58
(foo as Magic)(5 )
59
59
```
60
60
61
+ * [ SR-11298] [ ] :
62
+
63
+ A class-constrained protocol extension, where the extended protocol does
64
+ not impose a class constraint, will now infer the constraint implicitly.
65
+
66
+ ``` swift
67
+ protocol Foo {}
68
+ class Bar : Foo {
69
+ var someProperty: Int = 0
70
+ }
71
+
72
+ // Even though 'Foo' does not impose a class constraint, it is automatically
73
+ // inferred due to the Self: Bar constraint.
74
+ extension Foo where Self : Bar {
75
+ var anotherProperty: Int {
76
+ get { return someProperty }
77
+ // As a result, the setter is now implicitly nonmutating, just like it would
78
+ // be if 'Foo' had a class constraint.
79
+ set { someProperty = newValue }
80
+ }
81
+ }
82
+ ```
83
+
84
+ As a result, this could lead to code that currently compiles today to throw an error.
85
+
86
+ ``` swift
87
+ protocol Foo {
88
+ var someProperty: Int { get set }
89
+ }
90
+
91
+ class Bar : Foo {
92
+ var someProperty = 0
93
+ }
94
+
95
+ extension Foo where Self : Bar {
96
+ var anotherProperty1: Int {
97
+ get { return someProperty }
98
+ // This will now error, because the protocol requirement
99
+ // is implicitly mutating and the setter is implicitly
100
+ // nonmutating.
101
+ set { someProperty = newValue } // Error
102
+ }
103
+ }
104
+ ```
105
+
106
+ ** Workaround** : Define a new mutable variable inside the setter that has a reference to ` self ` :
107
+
108
+ ``` swift
109
+ var anotherProperty1: Int {
110
+ get { return someProperty }
111
+ set {
112
+ var mutableSelf = self
113
+ mutableSelf.someProperty = newValue // Okay
114
+ }
115
+ }
116
+ ```
117
+
61
118
* [ SE-0253] [ ] :
62
119
63
120
Values of types that declare ` func callAsFunction ` methods can be called
@@ -83,7 +140,7 @@ Swift 5.2
83
140
84
141
* [ SR-4206] [ ] :
85
142
86
- A method override is no longer allowed to have a generic signature with
143
+ A method override is no longer allowed to have a generic signature with
87
144
requirements not imposed by the base method. For example:
88
145
89
146
```
@@ -7799,4 +7856,5 @@ Swift 1.0
7799
7856
[SR- 8974 ]: < https: // bugs.swift.org/browse/SR-8974>
7800
7857
[SR- 9043 ]: < https: // bugs.swift.org/browse/SR-9043>
7801
7858
[SR- 9827 ]: < https: // bugs.swift.org/browse/SR-9827>
7859
+ [SR- 11298 ]: < https: // bugs.swift.org/browse/SR-11298>
7802
7860
[SR- 11429 ]: < https: // bugs.swift.org/browse/SR-11429>
0 commit comments