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

Support Coercing an Anonymous Struct Literal to an Error Union #11443

Closed
ominitay opened this issue Apr 15, 2022 · 3 comments
Closed

Support Coercing an Anonymous Struct Literal to an Error Union #11443

ominitay opened this issue Apr 15, 2022 · 3 comments

Comments

@ominitay
Copy link
Contributor

Disclaimer: This is kind-of a proposal and kind-of a bug, so I'm not sure how this should be labelled.

The Problem

Presently, attempting to return a struct from a fallible function using an anonymous struct literal will fail, with the error: type 'ErrorSet!StructType' does not support struct initialization syntax. I believe this to be a deficiency in the current implementation of Zig, especially if #5038 were to be accepted and implemented. The current behaviour is an unnecessary implementation as far as I can tell, and makes code more verbose than necessary or desirable.

The Solution

There are two possible solutions here. Firstly, to simply allow this coercion to be made. I don't see any fundamental contradictions here which would prevent this from working. Alternatively, #7812 would also address this, as returning values would be separated from throwing errors.

cc: @gracefuu
related: #5038 #7812

@Vexu
Copy link
Member

Vexu commented Apr 15, 2022

Something like this #10925?

@nektro
Copy link
Contributor

nektro commented Apr 15, 2022

yeah this is fixed in stage2. it was a limitation of the stage1 coercing checks but an easy fix since .{ } can never be an error value.

@ominitay
Copy link
Contributor Author

Glad to see it's fixed in the self-hosted compiler! Apologies for opening this then, but GitHub's search feature isn't so helpful...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants