| author | |
| committer | |
| log | 2b5bd56a67a26cd4adff76b6e3bf542e97f91cc4 |
| tree | 1fb2a33f508353cf91a9486b83d3706706607b2d |
| parent | ffc116de78dee6db8b3f2e0474f21bd88ef3895c |
2 files changed, 26 insertions(+), 1 deletions(-)
src/AstGen.zig+4-1| ... | ... | @@ -11359,7 +11359,10 @@ const GenZir = struct { |
| 11359 | 11359 | parent_gz.instructions.items.len -= src - dst; |
| 11360 | 11360 | as_scope.instructions_top = GenZir.unstacked_top; |
| 11361 | 11361 | // as_scope now unstacked, can add new instructions to parent_gz |
| 11362 | const casted_result = try parent_gz.addBin(.as, dest_type, result); | |
| 11362 | const casted_result = try parent_gz.addPlNode(.as_node, src_node, Zir.Inst.As{ | |
| 11363 | .dest_type = dest_type, | |
| 11364 | .operand = result, | |
| 11365 | }); | |
| 11363 | 11366 | return rvalue(parent_gz, ri, casted_result, src_node); |
| 11364 | 11367 | } else { |
| 11365 | 11368 | // implicitly move all as_scope instructions to parent_gz |
test/cases/compile_errors/invalid_coercion_in_aggregate_literal.zig created+22| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | export fn invalidArrayElem() u8 { | |
| 2 | const array_literal = [1]u8{@as(u8, 256)}; | |
| 3 | return array_literal[0]; | |
| 4 | } | |
| 5 | ||
| 6 | export fn invalidTupleElem() u8 { | |
| 7 | const tuple_literal = struct { u8 }{@as(u8, 256)}; | |
| 8 | return tuple_literal[0]; | |
| 9 | } | |
| 10 | ||
| 11 | export fn invalidStructField() u8 { | |
| 12 | const struct_literal = struct { field: u8 }{ .field = @as(u8, 256) }; | |
| 13 | return struct_literal.field; | |
| 14 | } | |
| 15 | ||
| 16 | // error | |
| 17 | // backend=stage2 | |
| 18 | // target=native | |
| 19 | // | |
| 20 | // :2:41: error: type 'u8' cannot represent integer value '256' | |
| 21 | // :7:49: error: type 'u8' cannot represent integer value '256' | |
| 22 | // :12:67: error: type 'u8' cannot represent integer value '256' |