Skip to content

Fix various resolved types of const pointers #2271

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

FnControlOption
Copy link
Contributor

@FnControlOption FnControlOption commented Apr 20, 2025

Alternative to #2265

  • Added a Binding struct that has two fields: type: Type and is_const: bool. Examples of when is_const is true are:
    1. An identifier that refers to a primitive, such as i32 and true
    2. An identifier foo that refers to a previously declared const foo
    3. An expression of the form &foo (i.e. &&foo is of type *const *Foo for a given var foo: Foo)
    4. A char/number/enum/string literal (i.e. &'a' is a *const comptime_int, &42 is a *const comptime_int, &.foo is a *const @Type(.enum_literal), &"foo" is a *const *const [3:0]u8)
  • Added three new functions: resolveBindingOfNode{,Internal,Uncached}
    • resolveTypeOfNode{,Internal} are now just helper functions that delegate to resolveBindingOfNode{,Internal}
    • resolveTypeOfNodeUncached still handles most AST nodes except for the following which are now handled by resolveBindingOfNodeUncached:
      • identifier
      • address_of
      • field_access
      • slice
      • slice_sentinel
      • slice_open
      • array_access
    • The current design allows most type resolution to happen in resolveTypeOfNodeUncached, while more special cases involving mutability can be handled in resolveBindingOfNodeUncached.

@FnControlOption FnControlOption changed the title Fix resolved type of pointer to const identifier Fix various resolved types of const pointers Apr 27, 2025
@FnControlOption
Copy link
Contributor Author

Updated PR description

@FnControlOption FnControlOption force-pushed the pointers2 branch 4 times, most recently from 1ebca86 to 44eb633 Compare May 1, 2025 14:44
This fixes the resolved types of pointers to:
- char literals,
- number literals,
- enum literals,
- string literals,
- error values,
- builtin function calls,
- and probably more
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.

1 participant