Skip to content

Commit 9ab363b

Browse files
committed
[BuilderTransform] Increase impact of unhandled statement fix
The impact should be very high because the whole body is skipped if the builder does not support some of the operations, otherwise the fix would interfere with result builders that do support operations but have syntactic issues in the body. Resolves: rdar://89880662 (cherry picked from commit 7fb1ea0)
1 parent 8d3f361 commit 9ab363b

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,8 +2480,10 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
24802480
}
24812481

24822482
// Record the first unhandled construct as a fix.
2483-
if (recordFix(SkipUnhandledConstructInResultBuilder::create(
2484-
*this, unsupported, builder, getConstraintLocator(locator)))) {
2483+
if (recordFix(
2484+
SkipUnhandledConstructInResultBuilder::create(
2485+
*this, unsupported, builder, getConstraintLocator(locator)),
2486+
/*impact=*/100)) {
24852487
return getTypeMatchFailure(locator);
24862488
}
24872489

test/Constraints/result_builder_diags.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,3 +938,32 @@ func test_dependent_member_with_unresolved_base_type() {
938938
}
939939
}
940940
}
941+
942+
// rdar://89880662 - incorrect error about unsupported control flow statement
943+
func test_impact_of_control_flow_fix() {
944+
@resultBuilder
945+
struct BuilderA {
946+
static func buildOptional<T>(_ value: T?) -> T? { return value }
947+
static func buildBlock<T>(_ v1: T) -> T { v1 }
948+
static func buildBlock<T, U>(_ v1: T, _ v2: U) -> (T, U) { (v1, v2) }
949+
}
950+
951+
@resultBuilder
952+
struct BuilderB {
953+
static func buildBlock<T>(_ v1: T) -> T { v1 }
954+
static func buildBlock<T, U>(_ v1: T, _ v2: U) -> (T, U) { (v1, v2) }
955+
}
956+
957+
func fn<T>(@BuilderA _: () -> T) {}
958+
func fn(@BuilderB _: () -> (Int?, Void)) {}
959+
960+
func test(_: Int) {}
961+
962+
fn {
963+
if true {
964+
0
965+
}
966+
967+
test("") // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
968+
}
969+
}

0 commit comments

Comments
 (0)