Skip to content
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

Swift 6 rethrows forcing "try" for a non-throwable closure #76769

Open
brustolin opened this issue Sep 29, 2024 · 1 comment
Open

Swift 6 rethrows forcing "try" for a non-throwable closure #76769

brustolin opened this issue Sep 29, 2024 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@brustolin
Copy link

brustolin commented Sep 29, 2024

Description

The following code snippet is not compiling under Swift 6, it works fine in Swift 5:

extension UIView{
   func addSubviews(_ views : [UIView]) {
      views.forEach(self.addSubview(_:))
   }
}

This is the workaround that works

func addSubviews(_ views : [UIView]) {
    views.forEach({ self.addSubview($0) })
}

Which is pretty much the same thing.

Environment

swift-driver version: 1.115
Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0

@brustolin brustolin added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Sep 29, 2024
@Kyle-Ye
Copy link
Contributor

Kyle-Ye commented Oct 18, 2024

I can reproduce it with AppKit or UIKit's addSubview.

But a custom (Int)->Void will not trigger the bug.

Also using Swift 6 compiler + Swift 5 Language mode will not trigger the bug.

import AppKit

func square(_ value: Int) -> Void {
    print(value * value)
}

@MainActor
func demo() {
    let array = [1, 2]
    array.forEach(square(_:))
    
    let root = NSView()
    let views: [NSView] = []
    views.forEach(root.addSubview(_:))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants