File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -1724,11 +1724,11 @@ tryCastToExistentialMetatype(
1724
1724
1725
1725
// A layer of functions that evaluate the source and/or destination types
1726
1726
// in order to invoke a tailored casting operation above.
1727
-
1727
+ //
1728
1728
// This layer also deals with general issues of unwrapping box types
1729
1729
// and invoking bridging conversions defined via the _ObjectiveCBridgeable
1730
1730
// protocol.
1731
-
1731
+ //
1732
1732
// Most of the caster functions above should be fairly simple:
1733
1733
// * They should deal with a single target type,
1734
1734
// * They should assume the source is fully unwrapped,
@@ -1942,6 +1942,11 @@ tryCast(
1942
1942
//
1943
1943
// 4. Try recursively unwrapping Optionals. First try jointly unwrapping
1944
1944
// both source and destination, then just destination, then just source.
1945
+ // Note that if both are optional, we try all three of these!
1946
+ // For example, consider casting an Optional<T> to
1947
+ // Optional<CustomDebugStringConvertible>. If T conforms, we need to
1948
+ // unwrap both. But if it doesn't, we unwrap just the destination
1949
+ // in order to cast Optional<T> to the protocol directly.
1945
1950
//
1946
1951
if (destKind == MetadataKind::Optional) {
1947
1952
if (srcKind == MetadataKind::Optional) {
You can’t perform that action at this time.
0 commit comments