-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed as duplicate of#66412
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
Compiles:
func ƒ<Value>(value: Value) -> Value {
switch value {
case let value: value
}
}
Does not compile:
extension Bool { // Type doesn't matter, though `Never` will crash the compiler.
init(value: Self) {
self = switch value {
case let value: value // This will compile with a warning, but assign the argument, not the bound value.
case let v: v // Cannot find 'v' in scope
}
}
}
Wrapping in a closure is a solution:
extension Bool {
init(value: Self) {
self = { switch value {
case let value: value
} } ()
}
}
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