You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Comptime (§17.6): str.bytes() / str.as_bytes() fails on (*self) as []u8 cast #3041
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
#3038, #3039, #3041, #3042, #2958: five spec-gap fixes from the #2987 …