-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
using a non-copyable type within a block that is marked NS_NOESCAPE in objc seems to cause a compiler error.
Reproduction
import Foundation
struct Foo: ~Copyable {}
func bar() {
var foo: Foo?
let arr = NSArray()
arr.enumerateObjects { _, _, _ in
foo = Foo()
}
_ = foo
}82532.swift:6:9: error: usage of a noncopyable type that compiler can't verify. This is a compiler bug. Please file a bug with a small example of the bug
4 |
5 | func bar() {
6 | var foo: Foo?
| `- error: usage of a noncopyable type that compiler can't verify. This is a compiler bug. Please file a bug with a small example of the bug
7 | let arr = NSArray()
8 | arr.enumerateObjects { _, _, _ in
Expected behavior
no error diagnostics, like you get when using a swift-implemented no-escape block:
import Foundation
struct Foo: ~Copyable {}
func bar() {
var foo: Foo?
let arr: NSArray = NSArray()
// arr.enumerateObjects { _, _, _ in
arr.forEach { _ in // ✅
foo = Foo()
}
_ = foo
}Environment
Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0
Additional information
originally reported via forum post with a slightly different example: https://forums.swift.org/t/swift-6-2-cant-verify-usage-of-a-noncopyable-type-and-wants-me-to-report-this-bug/82532
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels