Skip to content

Commit

Permalink
Correct scope change of objc id var and explain.
Browse files Browse the repository at this point in the history
Swift SVN r24821
  • Loading branch information
stormbrew committed Jan 29, 2015
1 parent 383dd5d commit 625ddfd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion stdlib/runtime/Casting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,11 @@ static bool _dynamicCastToExistential(OpaqueValue *dest,
const Metadata *srcType,
const ExistentialTypeMetadata *targetType,
DynamicCastFlags flags) {
#if SWIFT_OBJC_INTEROP
// This variable's lifetime needs to be for the whole function, but is
// only valid with Objective-C interop enabled.
id tmp;
#endif
// Find the actual type of the source.
OpaqueValue *srcDynamicValue;
const Metadata *srcDynamicType;
Expand All @@ -785,9 +790,10 @@ static bool _dynamicCastToExistential(OpaqueValue *dest,
// Class metadata can be used as an object when ObjC interop is available.
auto metatypePtr = reinterpret_cast<const Metadata **>(src);
auto metatype = *metatypePtr;
tmp = swift_dynamicCastMetatypeToObjectConditional(metatype);
// If the cast succeeded, use the result value as the class instance
// below.
if (id tmp = swift_dynamicCastMetatypeToObjectConditional(metatype)) {
if (tmp) {
srcDynamicValue = reinterpret_cast<OpaqueValue*>(&tmp);
srcDynamicType = reinterpret_cast<const Metadata*>(tmp);
break;
Expand Down

0 comments on commit 625ddfd

Please sign in to comment.