Commit e1b76fde by Ian Lance Taylor

compiler: explicitly convert between type aliases

    
    Otherwise we can get a crash in the backend.
    
    Test case is https://golang.org/cl/73790.
    
    Reviewed-on: https://go-review.googlesource.com/73810

From-SVN: r254126
parent 1cef1159
a409ac2c78899e638a014c97891925bec93cb3ad 64d570c590a76921cbdca4efb22e4675e19cc809
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -144,8 +144,8 @@ Expression::convert_for_assignment(Gogo*, Type* lhs_type, ...@@ -144,8 +144,8 @@ Expression::convert_for_assignment(Gogo*, Type* lhs_type,
|| rhs->is_error_expression()) || rhs->is_error_expression())
return Expression::make_error(location); return Expression::make_error(location);
if (lhs_type->forwarded() != rhs_type->forwarded() bool are_identical = Type::are_identical(lhs_type, rhs_type, false, NULL);
&& lhs_type->interface_type() != NULL) if (!are_identical && lhs_type->interface_type() != NULL)
{ {
if (rhs_type->interface_type() == NULL) if (rhs_type->interface_type() == NULL)
return Expression::convert_type_to_interface(lhs_type, rhs, location); return Expression::convert_type_to_interface(lhs_type, rhs, location);
...@@ -153,8 +153,7 @@ Expression::convert_for_assignment(Gogo*, Type* lhs_type, ...@@ -153,8 +153,7 @@ Expression::convert_for_assignment(Gogo*, Type* lhs_type,
return Expression::convert_interface_to_interface(lhs_type, rhs, false, return Expression::convert_interface_to_interface(lhs_type, rhs, false,
location); location);
} }
else if (lhs_type->forwarded() != rhs_type->forwarded() else if (!are_identical && rhs_type->interface_type() != NULL)
&& rhs_type->interface_type() != NULL)
return Expression::convert_interface_to_type(lhs_type, rhs, location); return Expression::convert_interface_to_type(lhs_type, rhs, location);
else if (lhs_type->is_slice_type() && rhs_type->is_nil_type()) else if (lhs_type->is_slice_type() && rhs_type->is_nil_type())
{ {
...@@ -165,8 +164,15 @@ Expression::convert_for_assignment(Gogo*, Type* lhs_type, ...@@ -165,8 +164,15 @@ Expression::convert_for_assignment(Gogo*, Type* lhs_type,
} }
else if (rhs_type->is_nil_type()) else if (rhs_type->is_nil_type())
return Expression::make_nil(location); 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. // No conversion is needed.
return rhs; return rhs;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment