[SR-12044] Mirror reflection returns zero children for nested single-case enum #54480
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
reflection
runtime
The Swift Runtime
Environment
Swift 5.2
Additional Detail from JIRA
md5: 134d940a232a6725abd31fd2b65b1e77
Issue Description:
If you nest a single-case enum in another enum and try to reflect on the outer enum case, you cannot reflect on this inner value. For example, the following prints an empty array:
enum Inner { case innermost }
enum Outer { case inner(Inner) }
print(Array(Mirror(reflecting: Outer.inner(.innermost)).children))
// prints "[]"
On the other hand, adding a case to the single-case enum restores the ability to reflect on it:
enum Inner { case innermost, innermost2 }
enum Outer { case inner(Inner) }
print(Array(Mirror(reflecting: Outer.inner(.innermost)).children))
// prints "[(label: Optional("inner"), value: Inner.innermost)]"
My current workaround involves checking the memory layout size of Inner and if it's zero then I unsafely bitcast a value of Void.
The text was updated successfully, but these errors were encountered: