@@ -28,6 +28,10 @@ func main_actor_int_pair() -> (Int, Int) {
28
28
return ( 0 , 0 )
29
29
}
30
30
31
+ func make_int( isolated isolation: ( any Actor ) ? = #isolation) -> Int {
32
+ return 0
33
+ }
34
+
31
35
// This test breaks because the intermediate argument is `nil`, which
32
36
// we treat as non-isolated.
33
37
@MainActor
@@ -121,3 +125,39 @@ func tupleIsolatedDefaultArg(x: (Int,Int) = main_actor_int_pair(),
121
125
func testTupleIsolatedDefaultArg( ) async {
122
126
await tupleIsolatedDefaultArg ( y: 0 )
123
127
}
128
+
129
+ // When a function is caller-isolated, its default argument generators
130
+ // should probably also be caller-isolated and forward their isolation
131
+ // properly when #isolation is used. Currently, however, that's not what
132
+ // we're doing, so test for the current behavior.
133
+
134
+ nonisolated ( nonsending)
135
+ func callerIsolatedDefaultArg( x: Int = make_int ( ) ) async { }
136
+
137
+ @MainActor
138
+ func useCallerIsolatedDefaultArg( ) async {
139
+ await callerIsolatedDefaultArg ( )
140
+ }
141
+
142
+ // Check that the default argument generator isn't caller-isolated.
143
+ // CHECK-LABEL: // default argument 0 of test.callerIsolatedDefaultArg
144
+ // CHECK-NEXT: // Isolation: unspecified
145
+ // CHECK-NEXT: sil hidden [ossa] @$s4test24callerIsolatedDefaultArg1xySi_tYaFfA_ :
146
+ // CHECK: bb0:
147
+ // Check that we provide a nil isolation for #isolation
148
+ // CHECK-NEXT: [[NIL_ISOLATION:%.*]] = enum $Optional<any Actor>, #Optional.none
149
+ // CHECK-NEXT: // function_ref test.make_int
150
+ // CHECK-NEXT: [[FN:%.*]] = function_ref @$s4test8make_int8isolatedSiScA_pSg_tF :
151
+ // CHECK-NEXT: [[RESULT:%.*]] = apply [[FN]]([[NIL_ISOLATION]])
152
+ // CHECK-NEXT: return [[RESULT]]
153
+
154
+ // Check that we pass the right isolation to the generator.
155
+ // CHECK-LABEL: sil hidden [ossa] @$s4test27useCallerIsolatedDefaultArgyyYaF :
156
+ // Get the main actor reference.
157
+ // CHECK: [[GET_MAIN_ACTOR:%.*]] = function_ref @$sScM6sharedScMvgZ :
158
+ // CHECK-NEXT: [[T0:%.*]] = apply [[GET_MAIN_ACTOR]](
159
+ // CHECK-NEXT: [[MAIN_ACTOR:%.*]] = begin_borrow [[T0]]
160
+ // Call the accessor.
161
+ // CHECK: // function_ref default argument 0 of
162
+ // CHECK-NEXT: [[GEN:%.*]] = function_ref @$s4test24callerIsolatedDefaultArg1xySi_tYaFfA_ :
163
+ // CHECK-NEXT: [[ARG:%.*]] = apply [[GEN]]()
0 commit comments