-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone
Description
Zig Version
0.14.0-dev.2577+271452d22
Steps to Reproduce and Observed Behavior
test "String literal shorter than n is quietly coerced into *const [n]u8" {
const alphabet: *const [64]u8 = "A";
@import("std").debug.print("{s}\n", .{alphabet});
}This will produce output that contains the string literal followed by random string data presumably present after the literal in memory.
Expected Behavior
I expected and would prefer that this fails at compile time. It makes some sense to me that a longer string literal would coerce into a pointer to a shorter string (which is also the case), but not the other way around, especially not in a way that places some undefined data in the array.
Happy Gregorian new year!
rohlem, nektro and cryptocode
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.