-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behavior when creating a slice of another slice #10684
Labels
Milestone
Comments
Note: changing const foo = "12345678";
var bar = foo[2..7]; // "34567"
const baz = bar[1..3]; // "45" |
using slices also makes it work const foo: []const u8 = "hello world";
const bar: []const u8 = foo[2..7];
const baz: []const u8 = bar[1..3]; but the bug remains when using the default types const foo: *const [11:0]u8 = "hello world";
const bar: *const [5]u8 = foo[2..7];
const baz: *const [2]u8 = bar[1..3]; |
More awkwardness: const std = @import("std");
pub fn main() !void {
const foo = "1234";
const bar = foo[0..4]; // "1234"
const s2 = bar[1..2]; // "2"
std.debug.print("s2: {s} {s}\n", .{ s2, @TypeOf(s2) }); // outputs 1 with type [1]u8
const s3 = bar[2..3]; // "3"
std.debug.print("s3: {s} {s}\n", .{ s3, @TypeOf(s3) }); // outputs 1 with type [1]u8
const s4 = bar[3..4]; // "4"
std.debug.print("s4: {s} {s}\n", .{ s4, @TypeOf(s4) }); // outputs 1 with type [1:0]u8
const s5 = bar[2..4]; // "3"
std.debug.print("s5: {s} {s}\n", .{ s5, @TypeOf(s5) }); // outputs 12 with type [2:0]u8
const s6 = bar[3..4]; // "3"
std.debug.print("s6: {s} {s}\n", .{ s6, @TypeOf(s6) }); // outputs 1 with type [1:0]u8
} output !zig run test.zig
s2: 1 *const [1]u8
s3: 1 *const [1]u8
s4: 1 *const [1:0]u8
s5: 12 *const [2:0]u8
s6: 1 *const [1:0]u8 I suspect quite abit comptime slice stuff is related (and was never fixed): #8304 #6905 |
wooster0
added a commit
to wooster0/zig
that referenced
this issue
Dec 7, 2022
wooster0
added a commit
to wooster0/zig
that referenced
this issue
Dec 7, 2022
wooster0
added a commit
to wooster0/zig
that referenced
this issue
Dec 7, 2022
wooster0
added a commit
to wooster0/zig
that referenced
this issue
Dec 8, 2022
wooster0
added a commit
to wooster0/zig
that referenced
this issue
Dec 8, 2022
wooster0
added a commit
to wooster0/zig
that referenced
this issue
Dec 9, 2022
kcbanner
pushed a commit
to kcbanner/zig
that referenced
this issue
Dec 10, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Zig Version
0.9.0
Steps to Reproduce
Expected Behavior
baz
is"45"
.Actual Behavior
baz
is"34"
.The text was updated successfully, but these errors were encountered: