| author | |
| committer | |
| log | 0cd953d40ea0f6934a0900f7ad8593e5deaf6efd |
| tree | b594359b1f26078553200d6510e983f3a859243a |
| parent | 13d04f9963be930360ab728edd47f1a6ecfb1777 |
Closes #47802 files changed, 15 insertions(+), 1 deletions(-)
src/ir.cpp+1-1| ... | ... | @@ -12819,7 +12819,7 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc |
| 12819 | 12819 | result->value->type = wanted_type; |
| 12820 | 12820 | return result; |
| 12821 | 12821 | } |
| 12822 | } else { | |
| 12822 | } else if (array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { | |
| 12823 | 12823 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_instr->source_node); |
| 12824 | 12824 | if (pointee == nullptr) |
| 12825 | 12825 | return ira->codegen->invalid_inst_gen; |
test/stage1/behavior/slice.zig+14| ... | ... | @@ -285,3 +285,17 @@ test "slice syntax resulting in pointer-to-array" { |
| 285 | 285 | S.doTheTest(); |
| 286 | 286 | comptime S.doTheTest(); |
| 287 | 287 | } |
| 288 | ||
| 289 | test "slice of hardcoded address to pointer" { | |
| 290 | const S = struct { | |
| 291 | fn doTheTest() void { | |
| 292 | const pointer = @intToPtr([*]u8, 0x04)[0..2]; | |
| 293 | comptime expect(@TypeOf(pointer) == *[2]u8); | |
| 294 | const slice: []const u8 = pointer; | |
| 295 | expect(@ptrToInt(slice.ptr) == 4); | |
| 296 | expect(slice.len == 2); | |
| 297 | } | |
| 298 | }; | |
| 299 | ||
| 300 | S.doTheTest(); | |
| 301 | } |