Skip to content

Add CHANGELOG entry for #41849 and #41978 #42360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ _**Note:** This is in reverse chronological order, so newer entries are added to

## Swift 5.7

* References to `optional` methods on a protocol metatype, as well as references to dynamically looked up methods on the `AnyObject` metatype are now supported. These references always have the type of a function that accepts a single argument and returns an optional value of function type:

```swift
class Object {
@objc func getTag() -> Int
}

@objc protocol P {
@objc optional func didUpdateObject(withTag tag: Int)
}

let getTag: (AnyObject) -> (() -> Int)? = AnyObject.getTag

let didUpdateObject: (any P) -> ((Int) -> Void)? = P.didUpdateObject
```

* [SE-0349][]:

Loading data from raw memory represented by `UnsafeRawPointer`,
Expand Down Expand Up @@ -98,7 +114,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
It's now possible to use a default value expression with a generic parameter type
to default the argument and its type:

```
```swift
func compute<C: Collection>(_ values: C = [0, 1, 2]) {
...
}
Expand Down
30 changes: 28 additions & 2 deletions test/Interpreter/dynamic_lookup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import Foundation

@objc protocol P {
@objc optional func e()
}

class X {
init() {}

Expand All @@ -15,11 +19,15 @@ class X {
return 17
}
}
extension X: P {
@objc func e() { print("X.e()") }
}

class Y {
init() {}
@objc class func g() { print("Y.g()") }
}
extension Y: P {}

class Z {
init() {}
Expand All @@ -44,7 +52,16 @@ func test_dynamic_lookup_f_unbound(_ obj: AnyObject) {
if of != nil {
of!()
} else {
print("Object does not respond to the selector \"f\".\n", terminator: "")
print("\(type(of: obj)) does not respond to the selector \"f\"")
}
}

func test_dynamic_lookup_e_unbound(_ obj: AnyObject) {
var oe = AnyObject.e(obj)
if oe != nil {
oe!()
} else {
print("\(type(of: obj)) does not respond to the selector \"e\"")
}
}

Expand Down Expand Up @@ -77,11 +94,20 @@ test_dynamic_lookup_f(Z())
print(type(of: AnyObject.f))
// CHECK-NEXT: X.f()
test_dynamic_lookup_f_unbound(X())
// CHECK-NEXT: Object does not respond to the selector "f"
// CHECK-NEXT: Y does not respond to the selector "f"
test_dynamic_lookup_f_unbound(Y())
// CHECK-NEXT: Z.f()
test_dynamic_lookup_f_unbound(Z())

// CHECK-NEXT: (AnyObject) -> Optional<() -> ()>
print(type(of: AnyObject.e))
// CHECK-NEXT: X.e()
test_dynamic_lookup_e_unbound(X())
// CHECK-NEXT: Y does not respond to the selector "e"
test_dynamic_lookup_e_unbound(Y())
// CHECK-NEXT: Z does not respond to the selector "e"
test_dynamic_lookup_e_unbound(Z())

// CHECK: Class does not respond to the selector "g"
test_dynamic_lookup_g(X())
// CHECK: Y.g()
Expand Down