Skip to content

Commit 4141e20

Browse files
committed
Revert "Allow existential opening for parameters of optional type."
This reverts commit 6e7fff7e65283ae9b25116fa6b75ba92fd2f2a58. The asymmetry between opening for optional parameters and optional arguments is surprising enough that we're currently opting not to allow them.
1 parent 0215216 commit 4141e20

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,10 +1402,8 @@ shouldOpenExistentialCallArgument(
14021402
if (param->isVariadic() && !param->getVarargBaseTy()->hasTypeSequence())
14031403
return None;
14041404

1405-
// Look through an inout and optional types on the formal type of the
1406-
// parameter.
1407-
auto formalParamTy = param->getInterfaceType()->getInOutObjectType()
1408-
->lookThroughSingleOptionalType();
1405+
// Look through an inout type on the formal type of the parameter.
1406+
auto formalParamTy = param->getInterfaceType()->getInOutObjectType();
14091407

14101408
// If the argument is of an existential metatype, look through the
14111409
// metatype on the parameter.
@@ -1414,8 +1412,8 @@ shouldOpenExistentialCallArgument(
14141412
paramTy = paramTy->getMetatypeInstanceType();
14151413
}
14161414

1417-
// Look through an inout and optional types on the parameter.
1418-
paramTy = paramTy->getInOutObjectType()->lookThroughSingleOptionalType();
1415+
// Look through an inout type on the parameter.
1416+
paramTy = paramTy->getInOutObjectType();
14191417

14201418
// The parameter type must be a type variable.
14211419
auto paramTypeVar = paramTy->getAs<TypeVariableType>();

test/Constraints/opened_existentials.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,6 @@ func passesInOut(i: Int) {
159159
takesInOut(&p)
160160
}
161161

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-
172162
@available(SwiftStdlib 5.1, *)
173163
func testReturningOpaqueTypes(p: any P) {
174164
let q = p.getQ()

0 commit comments

Comments
 (0)