-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
assignmentsFeature → expressions: assignmentsFeature → expressions: assignmentsbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfexpressionsFeature: expressionsFeature: expressionsswift 5.9switchFeature → statements: 'switch' statementsFeature → statements: 'switch' statementstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error
Description
Description
Function foo1
will not compile but function foo2
will. Compilator error is Cannot find 'val' in scope
. The difference is only with declaration and initialization of bar
variable.
func foo1() {
let value: Int? = nil
var bar: Int = 1
bar = switch value {
case let val?: val
default: 0
}
}
func foo2() {
let value: Int? = nil
var bar: Int = switch value {
case let val?: val
default: 0
}
}
Steps to reproduce
Try to compile above code in Xcode 15.0 beta.
Expected behavior
Both functions compile.
Environment
- Swift compiler version info
swift-driver version: 1.82.2 Apple Swift version 5.9 (swiftlang-5.9.0.114.6 clang-1500.0.27.1)
Target: arm64-apple-macosx13.0
- Xcode version info
Version 15.0 beta (15A5160n)
- Deployment target:
iOS 17.0
Metadata
Metadata
Assignees
Labels
assignmentsFeature → expressions: assignmentsFeature → expressions: assignmentsbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfexpressionsFeature: expressionsFeature: expressionsswift 5.9switchFeature → statements: 'switch' statementsFeature → statements: 'switch' statementstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error