Skip to content

Commit 1162ed6

Browse files
committed
[runtime] Report an error for casting failure in _bridgeNonVerbatimFromObjectiveC
1 parent d467b6f commit 1162ed6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

stdlib/public/runtime/Casting.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,14 +3023,17 @@ _bridgeNonVerbatimFromObjectiveC(
30233023
const_cast<void*>(swift_dynamicCastUnknownClass(sourceValue,
30243024
objectiveCType));
30253025

3026-
if (sourceValueAsObjectiveCType) {
3027-
// The type matches. _forceBridgeFromObjectiveC returns `Self`, so
3028-
// we can just return it directly.
3029-
bridgeWitness->forceBridgeFromObjectiveC(
3030-
static_cast<HeapObject*>(sourceValueAsObjectiveCType),
3031-
destValue, nativeType, nativeType, bridgeWitness);
3032-
return;
3026+
if (!sourceValueAsObjectiveCType) {
3027+
swift::swift_dynamicCastFailure(_swift_getClass(sourceValue),
3028+
objectiveCType);
30333029
}
3030+
3031+
// The type matches. _forceBridgeFromObjectiveC returns `Self`, so
3032+
// we can just return it directly.
3033+
bridgeWitness->forceBridgeFromObjectiveC(
3034+
static_cast<HeapObject*>(sourceValueAsObjectiveCType),
3035+
destValue, nativeType, nativeType, bridgeWitness);
3036+
return;
30343037
}
30353038

30363039
// Fail.

0 commit comments

Comments
 (0)