compiler: explicitly convert between type aliases
Otherwise we can get a crash in the backend.
Test case is https://golang.org/cl/73790.
Change-Id: I78e4c962d63308c971ad35b9f92b8de30f4d413e
Reviewed-on: https://go-review.googlesource.com/73810
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/go/expressions.cc b/go/expressions.cc
index 8337cbe..dad22eb 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -144,8 +144,8 @@
|| rhs->is_error_expression())
return Expression::make_error(location);
- if (lhs_type->forwarded() != rhs_type->forwarded()
- && lhs_type->interface_type() != NULL)
+ bool are_identical = Type::are_identical(lhs_type, rhs_type, false, NULL);
+ if (!are_identical && lhs_type->interface_type() != NULL)
{
if (rhs_type->interface_type() == NULL)
return Expression::convert_type_to_interface(lhs_type, rhs, location);
@@ -153,8 +153,7 @@
return Expression::convert_interface_to_interface(lhs_type, rhs, false,
location);
}
- else if (lhs_type->forwarded() != rhs_type->forwarded()
- && rhs_type->interface_type() != NULL)
+ else if (!are_identical && rhs_type->interface_type() != NULL)
return Expression::convert_interface_to_type(lhs_type, rhs, location);
else if (lhs_type->is_slice_type() && rhs_type->is_nil_type())
{
@@ -165,8 +164,15 @@
}
else if (rhs_type->is_nil_type())
return Expression::make_nil(location);
- else if (Type::are_identical(lhs_type, rhs_type, false, NULL))
+ else if (are_identical)
{
+ if (lhs_type->forwarded() != rhs_type->forwarded())
+ {
+ // Different but identical types require an explicit
+ // conversion. This happens with type aliases.
+ return Expression::make_cast(lhs_type, rhs, location);
+ }
+
// No conversion is needed.
return rhs;
}