Xcode 14 beta 4 - warnings about unused return values even when using @discardableResult

Viewed 309

In Xcode 14 beta 4 (and perhaps earlier betas but I haven't checked) I'm seeing warnings about unused return values even though the methods are annotated with @discardableResult. These warnings only surface for async methods, and as far as I can tell, only in extensions on UIKit classes:

import UIKit

extension UIView {
  @discardableResult
  func discardableUIKit() async -> Int {
    42
  }

  @discardableResult
  func discardableUIKit() -> Int {
    42
  }
}

extension NSObject {
  @discardableResult
  func discardableNSObject() async -> Int {
    42
  }

  @discardableResult
  func discardableNSObject() -> Int {
    42
  }
}

extension NSNumber {
  @discardableResult
  func discardableNSNumber() async -> Int {
    42
  }

  @discardableResult
  func discardableNSNumber() -> Int {
    42
  }
}

func test() {
  UIView().discardableUIKit()
  NSNumber().discardableNSObject()
  NSNumber().discardableNSNumber()
  Task {
    await UIView().discardableUIKit() // Result of call to function returning 'Int' is unused
    await NSNumber().discardableNSObject()
    await NSNumber().discardableNSNumber()
  }
}

I don't see these warnings in Xcode 13. Is this a bug or something new to Xcode 14/Swift 5.7 that I'm unaware of?

Update

As mentioned in the comments, this is a bug with Swift 5.7 that affects any type that is annotated with @MainActor. Presumably it will be fixed before the GM is released, but it is still present in Xcode 14 beta 5.

0 Answers
Related