Skip to content

Commit 5436180

Browse files
compiler: check slice to pointer-to-array conversion element type
When checking a slice to pointer-to-array conversion, I forgot to verify that the elements types are identical. For golang/go#395 Change-Id: I533ac52c0b390af96fce78a8c468ae9d8ad79da9 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/339329 Trust: Ian Lance Taylor <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 0a4d612 commit 5436180

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

go/expressions.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3962,7 +3962,10 @@ Type_conversion_expression::do_lower(Gogo*, Named_object*,
39623962
if (type->points_to() != NULL
39633963
&& type->points_to()->array_type() != NULL
39643964
&& !type->points_to()->is_slice_type()
3965-
&& val->type()->is_slice_type())
3965+
&& val->type()->is_slice_type()
3966+
&& Type::are_identical(type->points_to()->array_type()->element_type(),
3967+
val->type()->array_type()->element_type(),
3968+
0, NULL))
39663969
{
39673970
Temporary_statement* val_temp = NULL;
39683971
if (!val->is_multi_eval_safe())

go/types.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,9 @@ Type::are_convertible(const Type* lhs, const Type* rhs, std::string* reason)
846846
if (rhs->is_slice_type()
847847
&& lhs->points_to() != NULL
848848
&& lhs->points_to()->array_type() != NULL
849-
&& !lhs->points_to()->is_slice_type())
849+
&& !lhs->points_to()->is_slice_type()
850+
&& Type::are_identical(lhs->points_to()->array_type()->element_type(),
851+
rhs->array_type()->element_type(), 0, reason))
850852
return true;
851853

852854
// An unsafe.Pointer type may be converted to any pointer type or to

0 commit comments

Comments
 (0)