Skip to content

Incorrect error location when integer type doesn't match into target integer size #16688

@dec05eba

Description

@dec05eba

Zig Version

0.12.0-dev.3+9c05810be

Steps to Reproduce and Observed Behavior

const std = @import("std");

fn nothing() void {} // error is incorrectly displayed here

fn toSeeHere() void {}

fn resize(allocator: std.mem.Allocator, size: i32) !void {
    const data = try allocator.alloc(u8, size); // error should be displayed here, alloc expects usize but we give it i32
    defer allocator.free(data);
}

test "incorrect error location on integer cast" {
    try resize(std.testing.allocator, 32);
}

error:

src/main.zig:3:1: error: expected type 'usize', found 'i32'
fn nothing() void {} // error is incorrectly displayed here
^~~~~~~~~~~~~~~~~
src/main.zig:3:1: note: unsigned 64-bit int cannot represent all possible signed 32-bit values
referenced by:
    test.incorrect error location on integer cast: src/main.zig:13:9

it mentions line 13, which is the call to resize, but it doesn't mention where in resize the error is.
It seems to always point the error at the first function in the file (that includes functions inside structs).

Expected Behavior

Show correct compile error location

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorerror messageThis issue points out an error message that is unhelpful and should be improved.frontendTokenization, parsing, AstGen, Sema, and Liveness.regressionIt worked in a previous version of Zig, but stopped working.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions