# A bug in 0.17's dereferencing comptime slices?

**URL:** <https://ziggit.dev/t/a-bug-in-0-17s-dereferencing-comptime-slices/17835>\
**Category:** Help\
**Tags:** language, compiler\
**Created:** [October 4, 2026, 5:13pm UTC](https://ziggit.dev/t/a-bug-in-0-17s-dereferencing-comptime-slices/17835 "2026-10-04T17:13:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zigo](https://ziggit.dev/user_avatar/ziggit.dev/zigo/32/2414_2.png) [@zigo](https://ziggit.dev/u/zigo)\
**Post date:** [October 4, 2026, 5:13pm UTC](https://ziggit.dev/t/a-bug-in-0-17s-dereferencing-comptime-slices/17835/1 "2026-10-04T17:13:57Z")

</div>

```zig
const print = @import("std").debug.print;

var x: [2]bool = .{false, true}; // global runtime value

pub fn main() void {
    // 's' is a comptime slice.
    const s: []bool = &x;
    print("{}\n", .{ @TypeOf(s) }); // []bool
    print("{}\n", .{ s[0] }); // false
    print("{}\n", .{ @TypeOf(s[0]) }); // bool
    print("{}\n", .{ @TypeOf(s.*) }); // bool (should be '[2]bool'?)
}

```

---

<div class="post-metadata">

**Author:** ![zigo](https://ziggit.dev/user_avatar/ziggit.dev/zigo/32/2414_2.png) [@zigo](https://ziggit.dev/u/zigo)\
**Post date:** [October 4, 2026, 5:17pm UTC](https://ziggit.dev/t/a-bug-in-0-17s-dereferencing-comptime-slices/17835/2 "2026-10-04T17:17:26Z")

</div>

And the following code doesn’t compile.

```zig
var x: [2]bool = .{false, true}; // global runtime value

pub fn main() void { // error: genSetReg called with a value larger than dst_reg
    const s: []bool = &x;
    const arr = s.*;
    _ = arr;
}

```

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [October 4, 2026, 5:19pm UTC](https://ziggit.dev/t/a-bug-in-0-17s-dereferencing-comptime-slices/17835/3 "2026-10-04T17:19:16Z")

</div>

Looks like the bug is more so in `@TypeOf`, seeing a dereference and returning the pointer child type without checking if the dereference is valid, silly considering only 2/4 pointer types support it.

Not sure why you expect the type of `deref []T` to be `[]T`

---

<div class="post-metadata">

**Author:** ![zigo](https://ziggit.dev/user_avatar/ziggit.dev/zigo/32/2414_2.png) [@zigo](https://ziggit.dev/u/zigo)\
**Post date:** [October 4, 2026, 5:28pm UTC](https://ziggit.dev/t/a-bug-in-0-17s-dereferencing-comptime-slices/17835/4 "2026-10-04T17:28:49Z")

</div>

> [@vulpesx](#):
>
> Not sure why you expect the type of `deref []T` to be `[]T`

Sorry, I meant `[2]bool` (instead of `[]bool`).

---

<div class="post-metadata">

**Author:** ![zigo](https://ziggit.dev/user_avatar/ziggit.dev/zigo/32/2414_2.png) [@zigo](https://ziggit.dev/u/zigo)\
**Post date:** [October 4, 2026, 5:41pm UTC](https://ziggit.dev/t/a-bug-in-0-17s-dereferencing-comptime-slices/17835/5 "2026-10-04T17:41:06Z")

</div>

Looks the problem only occurs for comptime slices derived from runtime global arrays.

```zig
const print = @import("std").debug.print;

var x: [3]u16 = .{ 1, 2, 3 };
const sx: []u16 = &x;

const y: [3]u16 = .{1, 2, 3};
const sy: []const u16 = &y;

pub fn main() void {
    print("{}\n", .{ @TypeOf(sx) }); // []u16
    print("{}\n", .{ @TypeOf(sy) }); // []const u16
    
    const ay = sy.*;
    print("{}\n", .{ ay[0] }); // 1
    
    const ax = sx.*;
    print("{}\n", .{ ax[0] }); // error: type 'u16' does not support indexing
}

```
