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 <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/go/expressions.cc b/go/expressions.cc
index 15c9eab..51a8b7e 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -3962,7 +3962,10 @@
if (type->points_to() != NULL
&& type->points_to()->array_type() != NULL
&& !type->points_to()->is_slice_type()
- && val->type()->is_slice_type())
+ && val->type()->is_slice_type()
+ && Type::are_identical(type->points_to()->array_type()->element_type(),
+ val->type()->array_type()->element_type(),
+ 0, NULL))
{
Temporary_statement* val_temp = NULL;
if (!val->is_multi_eval_safe())
diff --git a/go/types.cc b/go/types.cc
index 7c7b2eb..0c44186 100644
--- a/go/types.cc
+++ b/go/types.cc
@@ -846,7 +846,9 @@
if (rhs->is_slice_type()
&& lhs->points_to() != NULL
&& lhs->points_to()->array_type() != NULL
- && !lhs->points_to()->is_slice_type())
+ && !lhs->points_to()->is_slice_type()
+ && Type::are_identical(lhs->points_to()->array_type()->element_type(),
+ rhs->array_type()->element_type(), 0, reason))
return true;
// An unsafe.Pointer type may be converted to any pointer type or to