Skip to content

Comptime (§17.6): str.bytes() / str.as_bytes() fails on (*self) as []u8 cast #3041

Closed

Description

@ehartford

Found during the #2987 manual audit of docs/spec/017_metaprogramming.md (§17.6, lines 462–469).

Minimal reproduction

comptime fn hash_str(s: str) -> u64:
    var h: u64 = 5381
    for c in s.bytes():
        h = h * 33 + c as u64
    h

const SHADER_PARAM_ID = comptime hash_str("world_matrix")
fn main:
    print(SHADER_PARAM_ID)

Actual

error: comptime cast is not supported for this value; reached through hash_str -> str.bytes -> str.as_bytes
 --> <embedded-std>/std/string.w:207:9
207 |         (*self) as []u8
    |         ^^^^^^^^^^^^^^^

Expected

str as []u8 in the comptime evaluator yields a u8 slice of the UTF-8 bytes of the string so str.as_bytes() and str.bytes() evaluate cleanly at compile time.

Activity

  1. added
    spec-gap
    on Nov 5, 2026
  2. added a commit that references this issue on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    spec-gap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions