- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
add @Here()
builtin for in-situ reference of known destination Type
#20236
Comments
seems like a duplicate of #16313 |
Wholly orthogonal. That one is for body access, this one is for callsite access. The builtin proposed there would be more comparable to a I’d suggest reading the discussion in #9938 for context. |
@Here()
builtin to make result type available for reference@Here()
builtin to make destination Type available for reference
@Here()
builtin to make destination Type available for reference@Here()
builtin for in-situ reference of known destination Type
Hm - the thing I don't like about this is that const a = MyEnum.foo;
const b: MyEnum = .foo;
const c: MyEnum = @Here().foo; I don't think that's a huge deal, but it's worth pointing out. |
Note that there is precedence to similar indeterminate-type builtins with those which require I’m also somewhat inclined to restrict the builtin to only access declarations and not union/enum members (cognitively it makes sense to have this “exception” being localized to a builtin as opposed to exceptions in the syntax rules itself), but I wouldn’t make it a strict requirement of this proposal. |
No, this builtin is different. Builtins like |
Hmm, I see what you mean. Would you say this is a similar problem to |
Seems similar to what I proposed in the #16313 (comment) Although you only get access to the current immediate type with |
It just occurred to me, how does |
|
Rejected in favour of #9938. |
This provides an alternative for usecase 1A and 2A in the accepted proposal #9938 to reduce its scope (and complexity debt) down to just the addition of a streamlined union-literal syntax without changing the current rules for explicit location inference of enum literals or imposing the namespace restriction described in @mlugg's acceptance notice.
From what I could see, the crux of the proposal was a need to access the destination namespace at callsite, in order to DRY destination types that are already explicitly known anyways.
The streamlining of union-literals in the original proposal seems to be adjacent to the motivation of callsite-type access, they are only syntactically related by the fact that Zig uses the same symbol for namespaced declarations and field access, but conceptually they are really two separate proposals.
By making the inferred namespace-access functionality into a builtin instead of a change to the syntax, not only is the functionality achieved with significantly less syntactic complexity, it also decouples the two disparate motivations of the original proposal into separate changes that can be evaluated on their individual merit.
Usecase demonstration
1A
2A
Using
@Here()
without an explicit result type will produce an error:The text was updated successfully, but these errors were encountered: