Skip to content

Commit 1846545

Browse files
committed
Use SwiftValue unpacking API correctly
1 parent 6127cc2 commit 1846545

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

stdlib/public/runtime/DynamicCast.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -433,21 +433,14 @@ tryCastUnwrappingSwiftValueSource(
433433
const Metadata *&destFailureType, const Metadata *&srcFailureType,
434434
bool takeOnSuccess, bool mayDeferChecks)
435435
{
436-
const Metadata *srcInnerType;
437-
const OpaqueValue *srcInnerValue;
438-
if (swift_unboxFromSwiftValueWithType(srcValue,
439-
reinterpret_cast<OpaqueValue *>(&srcInnerValue), &srcInnerType)) {
440-
return DynamicCastResult::SuccessViaCopy;
441-
}
436+
assert(srcType->getKind() == MetadataKind::Class);
442437

443-
// Note: We never `take` the contents from a SwiftValue box as
444-
// it might have other references. Instead, let our caller
445-
// destroy the reference if necessary.
446-
return tryCast(
447-
destLocation, destType,
448-
const_cast<OpaqueValue *>(srcInnerValue), srcInnerType,
449-
destFailureType, srcFailureType,
450-
/*takeOnSuccess=*/ false, mayDeferChecks);
438+
// unboxFromSwiftValueWithType is really just a recursive casting operation...
439+
if (swift_unboxFromSwiftValueWithType(srcValue, destLocation, destType)) {
440+
return DynamicCastResult::SuccessViaCopy;
441+
} else {
442+
return DynamicCastResult::Failure;
443+
}
451444
}
452445
#endif
453446

0 commit comments

Comments
 (0)