Skip to content

Commit 516b3e4

Browse files
authored
Merge pull request swiftlang#30195 from hborla/function-builder-crash
[ConstraintSystem] Bail out of applyFunctionBuilderBodyTransform if there is a failure in constraint generation.
2 parents a60ffb9 + e3239ba commit 516b3e4

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,11 +1297,13 @@ Optional<BraceStmt *> TypeChecker::applyFunctionBuilderBodyTransform(
12971297
func->getBody()->walk(walker);
12981298
}
12991299

1300-
// FIXME: check the result
1301-
cs.matchFunctionBuilder(func, builderType, resultContextType,
1302-
resultConstraintKind,
1303-
/*calleeLocator=*/cs.getConstraintLocator(fakeAnchor),
1304-
/*FIXME:*/cs.getConstraintLocator(fakeAnchor));
1300+
if (auto result = cs.matchFunctionBuilder(
1301+
func, builderType, resultContextType, resultConstraintKind,
1302+
/*calleeLocator=*/cs.getConstraintLocator(fakeAnchor),
1303+
/*FIXME:*/cs.getConstraintLocator(fakeAnchor))) {
1304+
if (result->isFailure())
1305+
return nullptr;
1306+
}
13051307

13061308
// Solve the constraint system.
13071309
SmallVector<Solution, 4> solutions;

test/Constraints/function_builder_diags.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,16 @@ func testNonExhaustiveSwitch(e: E) {
414414
}
415415
}
416416
}
417+
418+
// rdar://problem/59856491
419+
struct TestConstraintGenerationErrors {
420+
@TupleBuilder var buildTupleFnBody: String {
421+
String(nothing) // expected-error {{use of unresolved identifier 'nothing'}}
422+
}
423+
424+
func buildTupleClosure() {
425+
tuplify(true) { _ in
426+
String(nothing) // expected-error {{use of unresolved identifier 'nothing'}}
427+
}
428+
}
429+
}

0 commit comments

Comments
 (0)