authorgravatar for info@bnoordhuis.nlBen Noordhuis <info@bnoordhuis.nl> 2018-02-07 20:38:49+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-07 14:38:49-05:00
log0090c2d70b89cc6b5ab02bdc02aa49c4caf71a5a
tree3ad1caa3ee17dc7ee71d19f343121f429b101f5d
parent917e6fe3707a82f76c48e484735b86937831451f

DRY 'is slice?' conditionals in parser (#750)


2 files changed, 3 insertions(+), 11 deletions(-)

src/analyze.cpp+1-5
......@@ -3380,11 +3380,7 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
33803380 }
33813381
33823382 // slice const
3383 if (expected_type->id == TypeTableEntryIdStruct &&
3384 actual_type->id == TypeTableEntryIdStruct &&
3385 expected_type->data.structure.is_slice &&
3386 actual_type->data.structure.is_slice)
3387 {
3383 if (is_slice(expected_type) && is_slice(actual_type)) {
33883384 TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;
33893385 TypeTableEntry *expected_ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry;
33903386 if ((!actual_ptr_type->data.pointer.is_const || expected_ptr_type->data.pointer.is_const) &&
src/ir.cpp+2-6
......@@ -6369,10 +6369,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
63696369 }
63706370
63716371 // implicit [N]T to []const T
6372 if (expected_type->id == TypeTableEntryIdStruct &&
6373 expected_type->data.structure.is_slice &&
6374 actual_type->id == TypeTableEntryIdArray)
6375 {
6372 if (is_slice(expected_type) && actual_type->id == TypeTableEntryIdArray) {
63766373 TypeTableEntry *ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry;
63776374 assert(ptr_type->id == TypeTableEntryIdPointer);
63786375
......@@ -6384,8 +6381,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
63846381 }
63856382
63866383 // implicit &const [N]T to []const T
6387 if (expected_type->id == TypeTableEntryIdStruct &&
6388 expected_type->data.structure.is_slice &&
6384 if (is_slice(expected_type) &&
63896385 actual_type->id == TypeTableEntryIdPointer &&
63906386 actual_type->data.pointer.is_const &&
63916387 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)