mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
AstGen: fix src loc for invalid coercions in tuple literals
This commit is contained in:
parent
ffc116de78
commit
2b5bd56a67
@ -11359,7 +11359,10 @@ const GenZir = struct {
|
|||||||
parent_gz.instructions.items.len -= src - dst;
|
parent_gz.instructions.items.len -= src - dst;
|
||||||
as_scope.instructions_top = GenZir.unstacked_top;
|
as_scope.instructions_top = GenZir.unstacked_top;
|
||||||
// as_scope now unstacked, can add new instructions to parent_gz
|
// as_scope now unstacked, can add new instructions to parent_gz
|
||||||
const casted_result = try parent_gz.addBin(.as, dest_type, result);
|
const casted_result = try parent_gz.addPlNode(.as_node, src_node, Zir.Inst.As{
|
||||||
|
.dest_type = dest_type,
|
||||||
|
.operand = result,
|
||||||
|
});
|
||||||
return rvalue(parent_gz, ri, casted_result, src_node);
|
return rvalue(parent_gz, ri, casted_result, src_node);
|
||||||
} else {
|
} else {
|
||||||
// implicitly move all as_scope instructions to parent_gz
|
// implicitly move all as_scope instructions to parent_gz
|
||||||
|
|||||||
@ -0,0 +1,22 @@
|
|||||||
|
export fn invalidArrayElem() u8 {
|
||||||
|
const array_literal = [1]u8{@as(u8, 256)};
|
||||||
|
return array_literal[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
export fn invalidTupleElem() u8 {
|
||||||
|
const tuple_literal = struct { u8 }{@as(u8, 256)};
|
||||||
|
return tuple_literal[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
export fn invalidStructField() u8 {
|
||||||
|
const struct_literal = struct { field: u8 }{ .field = @as(u8, 256) };
|
||||||
|
return struct_literal.field;
|
||||||
|
}
|
||||||
|
|
||||||
|
// error
|
||||||
|
// backend=stage2
|
||||||
|
// target=native
|
||||||
|
//
|
||||||
|
// :2:41: error: type 'u8' cannot represent integer value '256'
|
||||||
|
// :7:49: error: type 'u8' cannot represent integer value '256'
|
||||||
|
// :12:67: error: type 'u8' cannot represent integer value '256'
|
||||||
Loading…
x
Reference in New Issue
Block a user