Skip to content

Commit 4677512

Browse files
authored
Merge pull request #84664 from jamieQ/fix-iso-default-param-idx-bug
[SILGen]: fix a bug in isolated default argument handling
2 parents 778281a + 7a4bc72 commit 4677512

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,6 +3210,7 @@ static void emitDelayedArguments(SILGenFunction &SGF,
32103210
// Otherwise, reset the current index adjustment.
32113211
} else {
32123212
indexAdjustment = 0;
3213+
indexAdjustmentSite = site;
32133214
}
32143215

32153216
assert(!siteArgs[argIndex] &&

test/SILGen/isolated_default_arguments.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,66 @@ func useCallerIsolatedDefaultArg() async {
161161
// CHECK: // function_ref default argument 0 of
162162
// CHECK-NEXT: [[GEN:%.*]] = function_ref @$s4test24callerIsolatedDefaultArg1xySi_tYaFfA_ :
163163
// CHECK-NEXT: [[ARG:%.*]] = apply [[GEN]]()
164+
165+
// The following tests failed due to a book-keeping error when processing delayed
166+
// isolated arguments in methods with:
167+
//
168+
// - a `self` parameter
169+
// - delayed arguments that expanded to zero or greater than one value
170+
// - a subsequent delayed argument
171+
//
172+
// https://github.com/swiftlang/swift/issues/84647
173+
174+
@MainActor
175+
enum E {
176+
static func tupleIsolatedDefaultArgStatic(
177+
_: Int,
178+
x: Int = main_actor_int_x(),
179+
// need not be isolated defaults
180+
tup: (Int, Int) = (1, 2),
181+
i: Int = 0
182+
) {}
183+
184+
static func voidIsolatedDefaultArgStatic(
185+
_: Int,
186+
v: Void = main_actor_void(),
187+
// need not be isolated defaults
188+
tup: (Int, Int) = (1, 2),
189+
i: Int = 0
190+
) {}
191+
}
192+
193+
func testTupleIsolatedDefaultArgStatic() async {
194+
await E.tupleIsolatedDefaultArgStatic(0)
195+
}
196+
197+
func testVoidIsolatedDefaultArgStatic() async {
198+
await E.voidIsolatedDefaultArgStatic(0)
199+
}
200+
201+
@MainActor
202+
final class Klazz {
203+
func tupleIsolatedDefaultArgInstanceMethod(
204+
_: Int,
205+
x: Int = main_actor_int_x(),
206+
// need not be isolated defaults
207+
tup: (Int, Int) = (1, 2),
208+
i: Int = 0
209+
) {}
210+
211+
func voidIsolatedDefaultArgInstanceMethod(
212+
_: Int,
213+
v: Void = main_actor_void(),
214+
// need not be isolated defaults
215+
tup: (Int, Int) = (1, 2),
216+
i: Int = 0
217+
) {}
218+
}
219+
220+
func testTupleIsolatedDefaultArgInstanceMethod(_ klazz: Klazz) async {
221+
await klazz.tupleIsolatedDefaultArgInstanceMethod(0)
222+
}
223+
224+
func testVoidIsolatedDefaultArgInstanceMethod(_ klazz: Klazz) async {
225+
await klazz.voidIsolatedDefaultArgInstanceMethod(0)
226+
}

0 commit comments

Comments
 (0)