Skip to content

Commit 54cb9df

Browse files
Merge pull request #24278 from aschwaighofer/initialize_extrainhabitantcount_single_case_enum
Initialize the extraInhabitantCount field of single case enums
2 parents 3d9b639 + 5014304 commit 54cb9df

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

stdlib/public/runtime/Enum.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ swift::swift_initEnumMetadataSingleCase(EnumMetadata *self,
5454
layout.size = payloadLayout->size;
5555
layout.stride = payloadLayout->stride;
5656
layout.flags = payloadLayout->flags.withEnumWitnesses(true);
57+
layout.extraInhabitantCount = payloadLayout->getNumExtraInhabitants();
5758

5859
vwtable->publishLayout(layout);
5960
}

test/Interpreter/enum_resilience.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,33 @@ ResilientEnumTestSuite.test("ResilientPrivateEnumMember") {
462462
_ = Container()
463463
}
464464

465+
struct Nested {
466+
var str: String
467+
var r: ResilientInt
468+
}
469+
470+
enum SingleCase {
471+
case only(nested: Nested)
472+
}
473+
474+
struct Status {
475+
let fst: SingleCase
476+
let snd: Bool
477+
}
478+
479+
func getOptional<T>(_ t: T) -> T? {
480+
return t
481+
}
482+
483+
func test<T>(_ t: T) {
484+
let o = getOptional(t)
485+
if let c = o {
486+
print("success")
487+
}
488+
}
489+
490+
ResilientEnumTestSuite.test("ResilientEnumSingleCase") {
491+
// This used to crash.
492+
test(Status(fst: .only(nested: Nested(str: "foobar", r: ResilientInt(i: 1))), snd: false))
493+
}
465494
runAllTests()

0 commit comments

Comments
 (0)