-
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.compilerThe Swift compiler itselfThe Swift compiler itselfexpressionsFeature: expressionsFeature: expressionsregressionswift 5.9switchFeature → statements: 'switch' statementsFeature → statements: 'switch' statementstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistype inferenceFeature: type inferenceFeature: type inferenceunexpected behaviorBug: Unexpected behavior or incorrect outputBug: Unexpected behavior or incorrect output
Description
With Swift 5.7 this code compiles fine:
class Foo {
private var action2: () -> Void = {}
func bar() {
let action = { [weak self] in
switch true {
case true:
self?.bar()
case false:
self?.bar()
}
}
self.action2 = action
}
}With Swift 5.8 it fails to compile because action is inferred as () -> ()? instead of () -> Void. I assume this is because of switch changing to be an expression, and now the optional result of self?.bar() is used as the return value, but since it breaks the build I figured I would report it anyways in case that's unexpected.
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.compilerThe Swift compiler itselfThe Swift compiler itselfexpressionsFeature: expressionsFeature: expressionsregressionswift 5.9switchFeature → statements: 'switch' statementsFeature → statements: 'switch' statementstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistype inferenceFeature: type inferenceFeature: type inferenceunexpected behaviorBug: Unexpected behavior or incorrect outputBug: Unexpected behavior or incorrect output