File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -1402,8 +1402,10 @@ shouldOpenExistentialCallArgument(
1402
1402
if (param->isVariadic() && !param->getVarargBaseTy()->hasTypeSequence())
1403
1403
return None;
1404
1404
1405
- // Look through an inout type on the formal type of the parameter.
1406
- auto formalParamTy = param->getInterfaceType()->getInOutObjectType();
1405
+ // Look through an inout and optional types on the formal type of the
1406
+ // parameter.
1407
+ auto formalParamTy = param->getInterfaceType()->getInOutObjectType()
1408
+ ->lookThroughSingleOptionalType();
1407
1409
1408
1410
// If the argument is of an existential metatype, look through the
1409
1411
// metatype on the parameter.
@@ -1412,8 +1414,8 @@ shouldOpenExistentialCallArgument(
1412
1414
paramTy = paramTy->getMetatypeInstanceType();
1413
1415
}
1414
1416
1415
- // Look through an inout type on the parameter.
1416
- paramTy = paramTy->getInOutObjectType();
1417
+ // Look through an inout and optional types on the parameter.
1418
+ paramTy = paramTy->getInOutObjectType()->lookThroughSingleOptionalType() ;
1417
1419
1418
1420
// The parameter type must be a type variable.
1419
1421
auto paramTypeVar = paramTy->getAs<TypeVariableType>();
Original file line number Diff line number Diff line change @@ -159,6 +159,16 @@ func passesInOut(i: Int) {
159
159
takesInOut ( & p)
160
160
}
161
161
162
+ func takesOptional< T: P > ( _ value: T ? ) { }
163
+ // expected-note@-1{{required by global function 'takesOptional' where 'T' = 'P'}}
164
+
165
+ func passesToOptional( p: any P , pOpt: ( any P ) ? ) {
166
+ takesOptional ( p) // okay
167
+ takesOptional ( pOpt) // expected-error{{protocol 'P' as a type cannot conform to the protocol itself}}
168
+ // expected-note@-1{{only concrete types such as structs, enums and classes can conform to protocols}}
169
+ }
170
+
171
+
162
172
@available ( SwiftStdlib 5 . 1 , * )
163
173
func testReturningOpaqueTypes( p: any P ) {
164
174
let q = p. getQ ( )
You can’t perform that action at this time.
0 commit comments