Files
zig/test/cases/compile_errors/leading_zero_in_integer.zig
zooster 4055e6055b AstGen: disallow leading zeroes in int literals and int types
This makes `0123` and `u0123` etc. illegal.

I'm now confident that this is a good change because
I actually caught two C header translation mistakes in `haiku.zig` with this.
Clearly, `0123` being octal in C (TIL) can cause confusion, and we make this easier to read by
requiring `0o` as the prefix and now also disallowing leading zeroes in integers.

For consistency and because it looks weird, we disallow it for integer types too (e.g. `u0123`).

Fixes #11963
Fixes #12417
2022-08-18 19:54:51 +03:00

28 lines
621 B
Zig

export fn entry1() void {
const T = u000123;
_ = T;
}
export fn entry2() void {
_ = i0;
_ = u0;
var x: i01 = 1;
_ = x;
}
export fn entry3() void {
_ = 000123;
}
export fn entry4() void {
_ = 01;
}
// error
// backend=llvm
// target=native
//
// :2:15: error: primitive integer type 'u000123' has leading zero
// :8:12: error: primitive integer type 'i01' has leading zero
// :12:9: error: integer literal '000123' has leading zero
// :12:9: note: use '0o' prefix for octal literals
// :15:9: error: integer literal '01' has leading zero
// :15:9: note: use '0o' prefix for octal literals