Skip to content

Commit 57c4b6a

Browse files
committed
[ResultBuilders] Fix handling of multiple pattern bindings
`SolutionApplicationTargetsKey` was constructing pattern binding entries with incorrect `kind`, which led to crashes for pattern bindings with multiple initialized entries.
1 parent 7249903 commit 57c4b6a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ class SolutionApplicationTargetsKey {
996996

997997
SolutionApplicationTargetsKey(
998998
const PatternBindingDecl *patternBinding, unsigned index) {
999-
kind = Kind::stmt;
999+
kind = Kind::patternBindingEntry;
10001000
storage.patternBindingEntry.patternBinding = patternBinding;
10011001
storage.patternBindingEntry.index = index;
10021002
}

test/Constraints/result_builder_diags.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ func testDiags() {
111111
y + 25
112112
}
113113

114+
tuplify(true) { _ in
115+
0
116+
let x: Int = 0, y: String = "" // Multiple initialized pattern bindings are okay
117+
x + 1
118+
y
119+
}
120+
114121
// Statements unsupported by the particular builder.
115122
tuplifyWithoutIf(true) {
116123
if $0 { // expected-error{{closure containing control flow statement cannot be used with result builder 'TupleBuilderWithoutIf'}}

0 commit comments

Comments
 (0)