You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,48 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
5
5
6
6
## Swift 5.7
7
7
8
+
* The compiler now emits a warning when a non-final class conforms to a protocol that imposes a same-type requirement between `Self` and an associated type. This is because such a requirement makes the conformance unsound for subclasses.
9
+
10
+
For example, Swift 5.6 would allow the following code, which at runtime would construct an instanec of `C` and not `SubC` as expected:
11
+
12
+
```swift
13
+
protocolP {
14
+
associatedtypeA : Q whereSelf==Self.A.B
15
+
}
16
+
17
+
protocolQ {
18
+
associatedtypeB
19
+
20
+
staticfuncgetB() -> B
21
+
}
22
+
23
+
classC : P {
24
+
typealiasA= D
25
+
}
26
+
27
+
classD : Q {
28
+
typealiasB= C
29
+
30
+
staticfuncgetB() -> C { returnC() }
31
+
}
32
+
33
+
extensionP {
34
+
staticfuncgetAB() ->Self {
35
+
// This is well-typed, because `Self.A.getB()` returns
36
+
// `Self.A.B`, which is equivalent to `Self`.
37
+
returnSelf.A.getB()
38
+
}
39
+
}
40
+
41
+
classSubC : C {}
42
+
43
+
// P.getAB() declares a return type of `Self`, so it should
44
+
// return `SubC`, but it actually returns a `C`.
45
+
print(SubC.getAB())
46
+
```
47
+
48
+
To make the above example correct, either the class `C` needs to become `final` (in which case `SubC` cannot be declared) or protocol `P` needs to be re-designed to not include the same-type requirement `Self == Self.A.B`.
49
+
8
50
*[SE-0341][]:
9
51
10
52
Opaque types can now be used in the parameters of functions and subscripts, wher they provide a shorthand syntax for the introduction of a generic parameter. For example, the following:
0 commit comments