mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Previously we would wait until CSApply, which would trigger their type-checking in `coercePatternToType`. This caused a number of bugs, and hampered solver-based completion, which does not run CSApply. Instead, form a conjunction of all the ExprPatterns present, which preserves some of the previous isolation behavior (though does not provide complete isolation). We can then modify `coercePatternToType` to accept a closure, which allows the solver to take over rewriting the ExprPatterns it has already solved. This then sets the stage for the complete removal of `coercePatternToType`, and doing all pattern type-checking in the solver.
63 lines
1.3 KiB
Swift
63 lines
1.3 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
// rdar://81228221
|
|
|
|
@resultBuilder
|
|
struct Builder {
|
|
static func buildBlock(_ components: Int...) -> Int { 0 }
|
|
static func buildEither(first component: Int) -> Int { 0 }
|
|
static func buildEither(second component: Int) -> Int { 0 }
|
|
static func buildOptional(_ component: Int?) -> Int { 0 }
|
|
static func buildArray(_ components: [Int]) -> Int { 0 }
|
|
}
|
|
|
|
@Builder
|
|
func foo(_ x: String) -> Int {
|
|
if .random() {
|
|
switch x {
|
|
case 1: // expected-error {{expression pattern of type 'Int' cannot match values of type 'String'}}
|
|
0
|
|
default:
|
|
1
|
|
}
|
|
}
|
|
}
|
|
|
|
@Builder
|
|
func bar(_ x: String) -> Int {
|
|
switch 0 {
|
|
case 0:
|
|
switch x {
|
|
case 1: // expected-error {{expression pattern of type 'Int' cannot match values of type 'String'}}
|
|
0
|
|
default:
|
|
1
|
|
}
|
|
default:
|
|
0
|
|
}
|
|
}
|
|
|
|
@Builder
|
|
func baz(_ x: String) -> Int {
|
|
do {
|
|
switch x {
|
|
case 1: // expected-error {{expression pattern of type 'Int' cannot match values of type 'String'}}
|
|
0
|
|
default:
|
|
1
|
|
}
|
|
}
|
|
}
|
|
|
|
@Builder
|
|
func qux(_ x: String) -> Int {
|
|
for _ in 0 ... 0 {
|
|
switch x {
|
|
case 1: // expected-error {{expression pattern of type 'Int' cannot match values of type 'String'}}
|
|
0
|
|
default:
|
|
1
|
|
}
|
|
}
|
|
}
|