diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-09-20 12:24:51 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-09-20 12:24:51 -0400 |
| commit | 9c8dfadbb1b95703a1503ae3a508f5acc29e7695 (patch) | |
| tree | e5884cb00c039385d68b1153a130cd6df0f80b77 /src/ir.cpp | |
| parent | f8fe517d126d582e37ab4537fe9fd42f0531f44b (diff) | |
| download | zig-9c8dfadbb1b95703a1503ae3a508f5acc29e7695.tar.gz zig-9c8dfadbb1b95703a1503ae3a508f5acc29e7695.zip | |
add compile error for casting const array to mutable slice
See #1565
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 79596d1d91..5e8d3c3a5a 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -10838,8 +10838,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst { ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; assert(slice_ptr_type->id == ZigTypeIdPointer); - if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type, - actual_type->data.pointer.child_type->data.array.child_type, source_node, + ZigType *array_type = actual_type->data.pointer.child_type; + bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 + || !actual_type->data.pointer.is_const); + if (const_ok && types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type, + array_type->data.array.child_type, source_node, !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk) { return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, wanted_type); |
