# Primitive type as field access expression

**URL:** <https://ziggit.dev/t/primitive-type-as-field-access-expression/17714>\
**Category:** Explain\
**Created:** [September 25, 2026, 5:01pm UTC](https://ziggit.dev/t/primitive-type-as-field-access-expression/17714 "2026-09-25T17:01:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![guifersv](https://ziggit.dev/user_avatar/ziggit.dev/guifersv/32/10022_2.png) [@guifersv](https://ziggit.dev/u/guifersv)\
**Post date:** [September 25, 2026, 5:01pm UTC](https://ziggit.dev/t/primitive-type-as-field-access-expression/17714/1 "2026-09-25T17:01:22Z")

</div>

why is this allowed

```zig
const std = @import("std");

pub fn main() void {
    std.debug.print("{any}\n", .{S.bool}); // ? prints true
    std.debug.print("{any}\n", .{S.@"bool"}); // identifier; prints true
}

const S = struct {
    pub const @"bool" = true;
};

```

---

<div class="post-metadata">

**Author:** ![castholm](https://ziggit.dev/user_avatar/ziggit.dev/castholm/32/1330_2.png) [@castholm](https://ziggit.dev/u/castholm)\
**Post date:** [September 25, 2026, 6:06pm UTC](https://ziggit.dev/t/primitive-type-as-field-access-expression/17714/2 "2026-09-25T18:06:20Z")

</div>

You probably already are aware but note that there is a distinction between keywords like `struct` or `error` and primitives like `bool` or `true`. Keywords must always be quoted regardless of context, whether they are declared or used as fields, decls, labels, etc. Primitives only need to be quoted in a decl context (i.e. `var`, `const`, `fn` or a function parameter), but not in other contexts such as declaring or accessing fields, **including accessing decls as fields via a namespace prefix.**

So, the following is expected:

```zig
const Foo = struct {
    const @"true": i32 = 0; // primitive
    const @"struct": i32 = 0; // keyword

    false: i32, // primitive
    @"union": i32, // keyword

    comptime {
        assert(@"true" == 0); // direct decl access
        assert(@"struct" == 0);
        assert(Foo.true == 0); // namespace field access
        assert(Foo.@"struct" == 0);

        const f: Foo = .{ .false = 0, .@"union" = 0 };
        assert(f.false == 0);
        assert(f.@"union" == 0);

        // enum literals also work like field accesses
        // basically, the rule of thumb is:
        // primitive after a dot . goes unquoted
        _ = .true;
        _ = .@"struct";
    }
};

```

---

<div class="post-metadata">

**Author:** ![Calder-Ty](https://ziggit.dev/user_avatar/ziggit.dev/calder-ty/32/10237_2.png) [@Calder-Ty](https://ziggit.dev/u/Calder-Ty)\
**Post date:** [September 25, 2026, 6:27pm UTC](https://ziggit.dev/t/primitive-type-as-field-access-expression/17714/3 "2026-09-25T18:27:27Z")

</div>

I’m surprised that bool isn’t a keyword.

---

<div class="post-metadata">

**Author:** ![alanza](https://ziggit.dev/user_avatar/ziggit.dev/alanza/32/6006_2.png) [@alanza](https://ziggit.dev/u/alanza)\
**Post date:** [September 25, 2026, 6:38pm UTC](https://ziggit.dev/t/primitive-type-as-field-access-expression/17714/4 "2026-09-25T18:38:03Z")

</div>

Would you be more or less surprised if the example used `usize`, which behaves the same way, instead?

---

<div class="post-metadata">

**Author:** ![PinieP](https://ziggit.dev/letter_avatar_proxy/v4/letter/p/58956e/32.png) [@PinieP](https://ziggit.dev/u/PinieP)\
**Post date:** [September 25, 2026, 6:46pm UTC](https://ziggit.dev/t/primitive-type-as-field-access-expression/17714/5 "2026-09-25T18:46:42Z")

</div>

I think I would have expected primitives to Work more or less lke consts/decls hidden somewhere in the compiler.  
But I guess being able to name a decl `@"true"` can be useful for auto generated code.

---

<div class="post-metadata">

**Author:** ![guifersv](https://ziggit.dev/user_avatar/ziggit.dev/guifersv/32/10022_2.png) [@guifersv](https://ziggit.dev/u/guifersv)\
**Post date:** [September 27, 2026, 1:59am UTC](https://ziggit.dev/t/primitive-type-as-field-access-expression/17714/6 "2026-09-27T01:59:39Z")

</div>

It doens’t need to be quoted on extern function

```zig
extern "c" fn dispatch_source_create(type: bool) void;
fn dispatch_source_create2(type: bool) void {}

```

```zig
An error occurred:
/tmp/playground3012446633/play.zig:7:28: error: name shadows primitive 'type'
fn dispatch_source_create2(type: bool) void {
                           ^~~~
/tmp/playground3012446633/play.zig:7:28: note: consider using @"type" to disambiguate

```
