Skip to content

Allow .ptr on pointer to array with ref result location #19416

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

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

Vexu
Copy link
Member

@Vexu Vexu commented Mar 24, 2024

Salvaging the useful parts of #19347

@mlugg
Copy link
Member

mlugg commented Mar 24, 2024

This contradicts #19414 - since comptime-vars are semantically mutable (albeit only with the ability to store the "correct" value), pointers to them are disallowed at runtime for all the same reasons as normal comptime vars.

@Vexu
Copy link
Member Author

Vexu commented Mar 24, 2024

It shouldn't since these are pointers to comptime-fields not pointers to fields of comptime-var structs.

@mlugg
Copy link
Member

mlugg commented Mar 24, 2024

Oops, sorry, typo in my earlier comment. That should say "comptime fields", not "comptime vars".

The problem, in short, is that comptime fields are weird -- pointers to them are considered mutable, it's just that Sema will emit a compile error if the stored value differs from the default. If we want to allow pointers to comptime fields to be emitted into runtime code, we will need to change the language to not consider comptime fields mutable, although probably special-case initialization expression to allow setting them (provided, of course, that the given value matches the default).

@Vexu Vexu changed the title Lower comptime field ptrs Allow .ptr on pointer to array with ref result location Mar 26, 2024
@Vexu Vexu enabled auto-merge (rebase) March 26, 2024 08:51
@Vexu Vexu merged commit 2d443cd into ziglang:master Mar 29, 2024
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

Successfully merging this pull request may close these issues.

2 participants