Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12044] Mirror reflection returns zero children for nested single-case enum #54480

Closed
stephencelis opened this issue Jan 16, 2020 · 2 comments
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

Comments

@stephencelis
Copy link
Contributor

Previous ID SR-12044
Radar rdar://problem/58861157
Original Reporter @stephencelis
Type Bug
Status Resolved
Resolution Done
Environment

Swift 5.2

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Reflection, Runtime
Assignee None
Priority Medium

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.

@beccadax
Copy link
Contributor

@swift-ci create

@slavapestov
Copy link
Member

#29901

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants