zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 39fa313ad881d242c4fbb6789bab26fed72449a2 (tree)
parent bf3d1c1aab336c4a650bb67dcaca132d4a0f6164
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Fri,  8 Jun 2018 14:57:16 -0400

disable some implicit casts for unknown length pointers

closes #770

Diffstat:
Msrc/ir.cpp | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/ir.cpp b/src/ir.cpp @@ -7994,6 +7994,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, // implicit &const [N]T to []const T if (is_slice(expected_type) && actual_type->id == TypeTableEntryIdPointer && + actual_type->data.pointer.ptr_len == PtrLenSingle && actual_type->data.pointer.is_const && actual_type->data.pointer.child_type->id == TypeTableEntryIdArray) { @@ -8012,6 +8013,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, // implicit [N]T to &const []const T if (expected_type->id == TypeTableEntryIdPointer && expected_type->data.pointer.is_const && + expected_type->data.pointer.ptr_len == PtrLenSingle && is_slice(expected_type->data.pointer.child_type) && actual_type->id == TypeTableEntryIdArray) { @@ -8074,6 +8076,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, actual_type->id == TypeTableEntryIdComptimeInt) { if (expected_type->id == TypeTableEntryIdPointer && + expected_type->data.pointer.ptr_len == PtrLenSingle && expected_type->data.pointer.is_const) { if (ir_num_lit_fits_in_other_type(ira, value, expected_type->data.pointer.child_type, false)) { @@ -8121,7 +8124,10 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, } // implicit enum to &const union which has the enum as the tag type - if (actual_type->id == TypeTableEntryIdEnum && expected_type->id == TypeTableEntryIdPointer) { + if (actual_type->id == TypeTableEntryIdEnum && + expected_type->id == TypeTableEntryIdPointer && + expected_type->data.pointer.ptr_len == PtrLenSingle) + { TypeTableEntry *union_type = expected_type->data.pointer.child_type; if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr) @@ -8141,7 +8147,11 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, // implicitly take a const pointer to something if (!type_requires_comptime(actual_type)) { TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); - if (types_match_const_cast_only(ira, expected_type, const_ptr_actual, source_node).id == ConstCastResultIdOk) { + if (expected_type->id == TypeTableEntryIdPointer && + expected_type->data.pointer.ptr_len == PtrLenSingle && + types_match_const_cast_only(ira, expected_type, const_ptr_actual, + source_node).id == ConstCastResultIdOk) + { return ImplicitCastMatchResultYes; } }