mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
IRGen: Fix reflection metadata for zero-sized enum cases
If an enum has a payload case with zero size, we treat it as an empty case for ABI purposes. Unfortunately, this meant that reflection metadata was incomplete for such cases, with a Mirror reporting that the enum value had zero children. Tweak the field type metadata emission slightly to preserve the payload type for such enum cases. Fixes <https://bugs.swift.org/browse/SR-12044> / <rdar://problem/58861157>.
This commit is contained in:
@@ -1145,6 +1145,28 @@ mirrors.test("Enum/SingletonNonGeneric/DefaultMirror") {
|
||||
}
|
||||
}
|
||||
|
||||
enum ZeroSizedEnumWithDefaultMirror {
|
||||
case π
|
||||
}
|
||||
|
||||
enum SingletonZeroSizedEnumWithDefaultMirror {
|
||||
case wrap(ZeroSizedEnumWithDefaultMirror)
|
||||
}
|
||||
|
||||
mirrors.test("Enum/SingletonZeroSizedEnumWithDefaultMirror/DefaultMirror") {
|
||||
do {
|
||||
let value = SingletonZeroSizedEnumWithDefaultMirror.wrap(.π)
|
||||
var output = ""
|
||||
dump(value, to: &output)
|
||||
|
||||
let expected =
|
||||
"▿ Mirror.SingletonZeroSizedEnumWithDefaultMirror.wrap\n" +
|
||||
" - wrap: Mirror.ZeroSizedEnumWithDefaultMirror.π\n"
|
||||
|
||||
expectEqual(expected, output)
|
||||
}
|
||||
}
|
||||
|
||||
enum SingletonGenericEnumWithDefaultMirror<T> {
|
||||
case OnlyOne(T)
|
||||
}
|
||||
@@ -2222,7 +2244,8 @@ if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) {
|
||||
testSTSDump(STSContainer.Cases<Int>.a(.init()),
|
||||
STSContainer℠.Cases<Int>.a(.init()),
|
||||
"""
|
||||
- Mirror.STSContainer<Mirror.STSOuter>.Cases<Swift.Int>.a\n
|
||||
▿ Mirror.STSContainer<Mirror.STSOuter>.Cases<Swift.Int>.a
|
||||
- a: Mirror.STSOuter\n
|
||||
""")
|
||||
|
||||
testSTSDump(STSContainer.Cases<Int>.b(.init()),
|
||||
|
||||
Reference in New Issue
Block a user