Skip to content

Commit 449aa71

Browse files
authored
Merge pull request #21120 from mikeash/existential-metatype-metadata-cast-fix-5.0
[5.0][Runtime] Fix incorrect cast in NonFixedExistentialMetatypeBox::Container::getNumWitnessTables.
2 parents 0088b36 + 2aae888 commit 449aa71

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

stdlib/public/runtime/ExistentialMetadataImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ struct LLVM_LIBRARY_VISIBILITY NonFixedExistentialMetatypeBox
624624
ExistentialMetatypeContainer Header;
625625

626626
static unsigned getNumWitnessTables(const Metadata *self) {
627-
auto castSelf = static_cast<const ExistentialTypeMetadata*>(self);
627+
auto castSelf = static_cast<const ExistentialMetatypeMetadata*>(self);
628628
return castSelf->Flags.getNumWitnessTables();
629629
}
630630

test/stdlib/Runtime.swift.gyb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,18 @@ Reflection.test("ObjectIdentifier/CustomDebugStringConvertible") {
666666

667667
}
668668

669+
class C: Q1 & Codable { }
670+
671+
Reflection.test("multiprotocolTypes") {
672+
// [SR-8158]: Printing type(of: Codable & Protocol type ) EXC_BAD_ACCESS
673+
// This use of String(reflecting:) exercises a previously incorrect cast in
674+
// NonFixedExistentialMetatypeBox::Container::getNumWitnessTables.
675+
let obj: Q1 & Codable = C()
676+
let t = type(of: obj)
677+
let x = String(reflecting: t)
678+
expectEqual("a.C", x)
679+
}
680+
669681

670682
var BitTwiddlingTestSuite = TestSuite("BitTwiddling")
671683

0 commit comments

Comments
 (0)