Open
Description
Description
SE-0360 introduced a possibility to return different types under #available
condition. But I found that it doesn't work with if
expressions introduced in SE-0380
Steps to reproduce
protocol P {}
struct S1: P {}
struct S2: P {}
// Compiles fine
func f1() -> some P {
if #available(macOS 99, *) {
return S1()
} else {
return S2()
}
}
// error: Branches have mismatching types 'S1' and 'S2'
func f2() -> some P {
if #available(macOS 99, *) {
S1()
} else {
S2()
}
}
Expected behavior
f2
compiles and behaves exactly as f1
Environment
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Xcode 15.0
Metadata
Metadata
Assignees
Labels
Feature → statements: Availability conditionThe @available attribute and availability checking in generalA deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfFeature: expressionsFeature → statements: 'if' statementsFeature → types → opaque types: opaque result typesFeature → types: opaque typesArea → compiler: Semantic analysis