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-5210] Indirect enum creates wrong case if one of cases has associated type with zero sized memory layout #47786

Closed
swift-ci opened this issue Jun 13, 2017 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5210
Radar None
Original Reporter kacperh (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9.0 beta 1, Swift Language version: 4.0(happens in 3.2 mode, too)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Miscompile
Assignee @aschwaighofer
Priority Medium

md5: b04453aa8a0203e62d26a57841de7531

relates to:

  • SR-5148 Indirect enum creates wrong case if associated type is an enum with a single case

Issue Description:

I have simple struct which works as configuration for network endpoint.
One problem is that without indirect keyword program crashes at runtime with cyclic metadata message. It's already reported as a bug in Swift JIRA.
Because Void is not decodable I've created this empty struct Nothing and conformed it to decodable.

struct Nothing: Decodable { }

struct EndpointConfiguration<Resource: Decodable> {
    indirect enum ResourceOrigin {
        case none(Resource)
        case json
    }
    let resourceType: ResourceOrigin
}
let config = EndpointConfiguration(
    resourceType: .none(Nothing())
)
print(config)

Prints:

EndpointConfiguration<Nothing>(resourceType: EndpointConfiguration<Nothing>.ResourceOrigin.json)

Which is very weird - it's not the case I specified I was thinking that it has to be something with memory layout and changed `Nothing` to this form:

struct Nothing: Decodable {
    private let x = 0
    init() { }
}

Now same usage prints:

EndpointConfiguration<Nothing>(resourceType: EndpointConfiguration<Nothing>.ResourceOrigin.none(Nothing(x: 0)))

Which is totally fine.

Minimal reproduction example:

struct S {}

enum E {
    indirect case a(S)
    case b
}

print(E.a(S()))

It's probably connected to S or Nothing having zero storage. With class it works as intended.

@belkadan
Copy link
Contributor

Possibly the same as SR-5148? cc aschwaighofer@apple.com (JIRA User)

@aschwaighofer
Copy link
Member

Yes this is the duplicate of SR-5148.

Whenever we have an indirect enum with an empty payload and a non payload case we map both to zero.

@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
Projects
None yet
Development

No branches or pull requests

3 participants