-
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 itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsFeature: expressionsswitchFeature → statements: 'switch' statementsFeature → statements: 'switch' statementstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
Description
Description
No response
Reproduction
enum SpellFieldDBv4 {
case spellid
case name
case school
}
struct SpellFieldsv4 {
var spellid : Int
var name : String
var school : String?
func stringVal(idx: SpellFieldDBv4) -> String? {
return switch idx {
case .name: name
case .school: school (1)
}
}
(1) Value of optional type 'String?' must be unwrapped to a value of type 'String'
Minimal XC project attached.
Expected behavior
No compiler error for that line.
Environment
Apple Swift version 6.2.1 (swiftlang-6.2.1.4.8 clang-1700.4.4.1)
Target: arm64-apple-macosx26.0
XC 26.1
Additional information
Work around is to drop 'return switch ...'
and use
switch idx {
case .school: return school
}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 itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsFeature: expressionsswitchFeature → statements: 'switch' statementsFeature → statements: 'switch' statementstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis