Skip to content

Commit 9031865

Browse files
authored
Merge pull request #20644 from jckarter/classify-dynamic-cast-future-proofing
Be conservative with classifying some casts that could change in the future.
2 parents bc9c876 + 1475d76 commit 9031865

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/SIL/DynamicCasts.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,10 @@ classifyDynamicCastToProtocol(ModuleDecl *M, CanType source, CanType target,
107107
if (!SourceNominalTy)
108108
return DynamicCastFeasibility::MaySucceed;
109109

110-
// If we are casting a protocol, then the cast will fail
111-
// as we have not found any conformances and protocols cannot
112-
// be extended currently.
113-
// NOTE: If we allow protocol extensions in the future, this
114-
// conditional statement should be removed.
115-
if (isa<ProtocolType>(source)) {
116-
return DynamicCastFeasibility::WillFail;
110+
// Protocol types may conform to their own protocols (or other protocols)
111+
// in the future.
112+
if (source->isAnyExistentialType()) {
113+
return DynamicCastFeasibility::MaySucceed;
117114
}
118115

119116
// If it is a class and it can be proven that this class and its
@@ -491,7 +488,9 @@ swift::classifyDynamicCast(ModuleDecl *M,
491488
sourceFunction.getResult() == targetFunction.getResult())
492489
return DynamicCastFeasibility::WillSucceed;
493490

494-
return DynamicCastFeasibility::WillFail;
491+
// Be conservative about function type relationships we may add in
492+
// the future.
493+
return DynamicCastFeasibility::MaySucceed;
495494
}
496495
}
497496

0 commit comments

Comments
 (0)