Files
zig/test/cases/compile_errors/break_void_result_location.zig
Jacob Young b9c4857ed6 AstGen: add source location to certain const initializers
Before:

    assign_local_bad_coercion.zig:5:1: error: expected type 'u32', found 'u64'
    export fn constEntry() u32 {
    ^~~~~~
    assign_local_bad_coercion.zig:11:19: error: expected type 'u32', found 'u64'
        var x: u32 = g();
                     ~^~

After:

    assign_local_bad_coercion.zig:6:21: error: expected type 'u32', found 'u64'
        const x: u32 = g();
                       ~^~
    assign_local_bad_coercion.zig:11:19: error: expected type 'u32', found 'u64'
        var x: u32 = g();
                     ~^~
2023-06-25 12:00:48 -07:00

33 lines
640 B
Zig

export fn f1() void {
const x: usize = for ("hello") |_| {};
_ = x;
}
export fn f2() void {
const x: usize = for ("hello") |_| {
break;
};
_ = x;
}
export fn f3() void {
var t: bool = true;
const x: usize = while (t) {
break;
};
_ = x;
}
export fn f4() void {
const x: usize = blk: {
break :blk;
};
_ = x;
}
// error
// backend=stage2
// target=native
//
// :2:22: error: expected type 'usize', found 'void'
// :7:9: error: expected type 'usize', found 'void'
// :14:9: error: expected type 'usize', found 'void'
// :19:27: error: expected type 'usize', found 'void'