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
+82Lines changed: 82 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,88 @@ CHANGELOG
28
28
Swift 5.4
29
29
---------
30
30
31
+
* Protocol conformance checking now considers `where` clauses when evaluating if a `typealias` is a suitable witness for an associated type requirement. The following code is now rejected:
32
+
33
+
```swift
34
+
protocolHolder {
35
+
associatedtypeContents
36
+
}
37
+
38
+
structBox<T> : Holder {}
39
+
// error: type 'Box<T>' does not conform to protocol 'Holder'
40
+
41
+
extensionBoxwhere T :Hashable {
42
+
typealiasContents= T
43
+
}
44
+
```
45
+
46
+
In most cases, the compiler would either crash or produce surprising results when making use of a `typealias` with an unsatisfied `where` clause, but it is possible that some previously-working code is now rejected. In the above example, the conformance can be fixed in one of various ways:
47
+
48
+
1) making it conditional (moving the `: Holder` from the definition of `Box` to the extension)
49
+
2) moving the `typealias` from the extension to the type itself
50
+
3) relaxing the `where` clause on the extension
51
+
52
+
* Availability checking now rejects protocols that refine less available protocols. Previously, this was accepted by the compiler but could result in linker errors or runtime crashes:
53
+
54
+
```swift
55
+
@available(macOS11, *)
56
+
protocolBase {}
57
+
58
+
protocolBad : Base{}
59
+
// error: 'Base' is only available in macOS 11 or newer
60
+
61
+
@available(macOS11, *)
62
+
protocolGood : Base{} // OK
63
+
```
64
+
65
+
* The `@available` attribute is no longer permitted on generic parameters, where it had no effect:
66
+
67
+
```swift
68
+
structBad<@available(macOS 11, *) T> {}
69
+
// error: '@available' attribute cannot be applied to this declaration
70
+
71
+
structGood<T> {} // equivalent
72
+
```
73
+
74
+
* If a type is made to conform to a protocol via an extension, the availability of the extension is now taken into account when forming generic types that use this protocol conformance. For example, consider a `Box` type whose conformance to `Hashable` uses features only available on macOS 11:
75
+
76
+
```swift
77
+
publicstructBox {}
78
+
79
+
@available(macOS11, *)
80
+
extensionBox : Hashable{
81
+
funchash(into: inout Hasher) {
82
+
// call some new API to hash the value...
83
+
}
84
+
}
85
+
86
+
publicfuncfindBad(_: Set<Box>) -> Box {}
87
+
// warning: conformance of 'Box' to 'Hashable' is only available in macOS 11 or newer
88
+
89
+
@available(macOS11, *)
90
+
publicfuncfindGood(_: Set<Box>) -> Box {} // OK
91
+
```
92
+
93
+
In the above code, it is not valid for `findBad()` to take a `Set<Box>`, since `Set` requires that its element type conform to `Hashable`; however the conformance of `Box` to `Hashable` is not available prior to macOS 11.
94
+
95
+
Note that using an unavailable protocol conformance is a warning, not an error, to avoid potential source compatibility issues. This is because it was technically possible to write code in the past that made use of unavailable protocol conformances but worked anyway, if the optimizer had serendipitously eliminated all runtime dispatch through this conformance, or the code in question was entirely unreachable at runtime.
96
+
97
+
Protocol conformances can also be marked as completely unavailable or deprecated, by placing an appropriate `@available` attribute on the extension:
@available(*, deprecated, message: "Suggest using something else")
104
+
extensionBox : Hashable{}
105
+
```
106
+
107
+
If a protocol conformance is defined on the type itself, it inherits availability from the type. You can move the protocol conformance to an extension if you need it to have narrower availability than the type.
108
+
109
+
* When `swift` is run with no arguments, it starts a REPL (read eval print loop) that uses LLDB. The compiler also had a second REPL implementation, known as the "integrated REPL", formerly accessible by running `swift -frontend -repl`. The "integrated REPL" was only intended for use by compiler developers, and has now been removed.
110
+
111
+
Note that this does not take away the ability to put Swift code in a script and run it with `swift myScript.swift`. This so-called "script mode" is distinct from the integrated REPL, and continues to be supported.
112
+
31
113
* Property wrappers now work in local contexts, making the following valid:
0 commit comments