-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
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.closuresFeature: closuresFeature: closurescompilerThe Swift compiler itselfThe Swift compiler itselfoptional bindingFeature → patterns: optional bindingFeature → patterns: optional bindingregressionresult buildersFeature: Result buildersFeature: Result buildersself capturesFeature → closures: 'self' capturesFeature → closures: 'self' capturesswift 5.8type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error
Description
Description
When I tried to compile with Xcode 14.3 RC 2, our company's project codes didn't compile with some reasons. One of that is this case. In resultBuilder closure, using weak capture self with if-let shorthand make capturing semantic error. I made a sample code snippet to reproduce problem.
Steps to reproduce
Try this sample
@resultBuilder
struct VoidBuilder {
static func buildBlock() -> Void {
}
static func buildPartialBlock<T>(first: T) -> Void {
}
static func buildPartialBlock<T>(accumulated: Void, next: T) -> Void {
}
}
final class EscapingWrapper {
static func wrapper(_ closure: @escaping () -> Void) {
closure()
}
}
final class Sample {
@VoidBuilder
var void: Void {
EscapingWrapper.wrapper { [weak self] in
guard let self else { return } // Implicit use of 'self' in closure; use 'self.' to make capture semantics explicit
}
}
}Expected behavior
compile success without error.
Environment
-
Swift compiler version info
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0 -
Xcode version info
Xcode 14.3
Build version 14E222b -
Deployment target
no specific target(It reproduced in both ios project and cmd project)
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.closuresFeature: closuresFeature: closurescompilerThe Swift compiler itselfThe Swift compiler itselfoptional bindingFeature → patterns: optional bindingFeature → patterns: optional bindingregressionresult buildersFeature: Result buildersFeature: Result buildersself capturesFeature → closures: 'self' capturesFeature → closures: 'self' capturesswift 5.8type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error