Skip to content

Confusing error message if you try to use a reversed range with "for" with comptime-known values #14758

Description

@mitchellh

Zig Version

0.11.0-dev.1817+f6c934677

Steps to Reproduce and Observed Behavior

const std = @import("std");

pub fn main() !void {
    for (5..0) |i| std.log.warn("i={}", .{i});
}
test.zig:4:11: error: type 'usize' cannot represent integer value '-5'
    for (5..0) |i| std.log.warn("i={}", .{i});                                                                                                                                                                                                                                                                                                         ~^~~
referenced by:
    comptime_0: /nix/store/06jkzn3j2w7h3m687gls19k9x0j3bsyz-zig-0.11.0-dev.1817+f6c934677/lib/std/start.zig:59:50
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Expected Behavior

I don't expect this to work but I expected to say something more helpful like reverse ranges not being allowed or something.

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

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions