Skip to content

Better error message when start is bigger than the end in for(start..end) #14701

@IntegratedQuantum

Description

@IntegratedQuantum

Zig Version

0.11.0-dev.1711+dc1f50e50

Steps to Reproduce and Observed Output

In continuation of #14700

const std = @import("std");

pub fn main() void {
	var start: u32 = 1;
	var end: u32 = 0;
	for(start..end) |x| {
		std.log.info("{}", .{x});
	}
}

At the moment this produces an integer overflow error:

thread 2222 panic: integer overflow
/home/mint/Desktop/test.zig:6:6: 0x20b56c in main (test)
 for(start..end) |x| {
     ^

Expected Output

I expect the error to be equivalent to the one we get for slicing:

thread 2319 panic: start index 1 is larger than end index 0
/home/mint/Desktop/test.zig:7:11: 0x20b60f in main (test)
 for(slice[start..end]) |x| {
          ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions