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

Regression compiling non-throwing compactMap #74558

Open
NachoSoto opened this issue Jun 19, 2024 · 2 comments
Open

Regression compiling non-throwing compactMap #74558

NachoSoto opened this issue Jun 19, 2024 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. throws & rethrows Feature → error handling: throws & rethrows type checker Area → compiler: Semantic analysis

Comments

@NachoSoto
Copy link
Contributor

NachoSoto commented Jun 19, 2024

Description

The following code compiles fine with Swift 5.x, but Swift 6 produces a bogus diagnostic.

Reproduction

import AppKit

open class Base: NSView {
  override public init(frame: NSRect) {
    super.init(frame: frame)
  }

  @available(*, unavailable)
  public required init?(coder _: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

final class Subview<View: NSView>: Base {
  var views: [View] {
    let views: [NSView] = []
    // Call can throw, but it is not marked with 'try' and the error is not handled
    return views.compactMap(f)
  }

  private func f(_ view: NSView) -> View? {
    return nil
  }
}

Expected behavior

The code should compile fine, but instead produces

Call can throw, but it is not marked with 'try' and the error is not handled

Environment

swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0

Additional information

I haven't been able to reduce this further without NSView.

@NachoSoto NachoSoto added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jun 19, 2024
@hborla hborla added type checker Area → compiler: Semantic analysis throws & rethrows Feature → error handling: throws & rethrows and removed triage needed This issue needs more specific labels labels Jul 14, 2024
@hborla
Copy link
Member

hborla commented Jul 14, 2024

I can't reproduce this on main

@NachoSoto
Copy link
Contributor Author

This is still reproducible with Xcode 16 RC.

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. throws & rethrows Feature → error handling: throws & rethrows type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants