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

langref: exemplify practical difference between !T and anyerror!T #21454

Open
Des-Nerger opened this issue Sep 19, 2024 · 3 comments
Open

langref: exemplify practical difference between !T and anyerror!T #21454

Des-Nerger opened this issue Sep 19, 2024 · 3 comments

Comments

@Des-Nerger
Copy link
Contributor

Des-Nerger commented Sep 19, 2024

Since anytype in Zig means type inference, people may be misled into thinking that anyerror also does mean type inference; but just for error types. And so, they may get an idea that !T is just an abbreviated and nicer way to write the "frequently used" anyerror!T combination.

I'm not suggesting changing the language itself here, but at least the reference should grab an attention to the distinction, give an example of where one of them could accomplish more than another, etc.

@Rexicon226
Copy link
Contributor

related: #5893

@nektro
Copy link
Contributor

nektro commented Sep 19, 2024

have you noticed this confusion happen in the wild? not saying we shouldnt add this but my initial reaction was that its unlikely given that anytype is the only any thats not a discrete type/value

@mnemnion
Copy link

Debatable whether anyopaque is discrete, seems more like anytype than not to me, but that's a tangent here. I agree that it's relatively unlikely that someone would think that !T could be replaced with anyerror!T without changing the meaning/type of the expression.

I wouldn't describe an anytype as type-inferred, I would describe it as type-generic. The anyerror documentation and that for inferred error sets seem pretty clear to me, is there something specific you feel is missing?

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

4 participants