diff mbox

Go patch committed: Correct types in type conversion

Message ID mcrsiv7fntc.fsf@iant-glaptop.roam.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Nov. 8, 2013, 5:46 a.m. UTC
This patch to the Go frontend fixes the type returned when a type
conversion has to make a function call.  I have a test case that I will
commit to the master testsuite after the Go 1.2 release (the test case
is simply "return []byte(s)[0]").  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff mbox

Patch

diff -r 3b96b48543bd go/expressions.cc
--- a/go/expressions.cc	Thu Nov 07 15:35:59 2013 -0800
+++ b/go/expressions.cc	Thu Nov 07 20:39:58 2013 -0800
@@ -3351,9 +3351,10 @@ 
 	  return se->get_tree(context);
 	}
 
-      Call_expression* i2s_expr =
+      Expression* i2s_expr =
           Runtime::make_call(Runtime::INT_TO_STRING, this->location(), 1,
                              this->expr_);
+      i2s_expr = Expression::make_cast(type, i2s_expr, this->location());
       ret = i2s_expr->get_tree(context);
     }
   else if (type->is_string_type() && expr_type->is_slice_type())
@@ -3405,7 +3406,7 @@ 
       Type* e = type->array_type()->element_type()->forwarded();
       go_assert(e->integer_type() != NULL);
 
-      Call_expression* s2a_expr;
+      Expression* s2a_expr;
       if (e->integer_type()->is_byte())
         s2a_expr = Runtime::make_call(Runtime::STRING_TO_BYTE_ARRAY,
                                       this->location(), 1, this->expr_);
@@ -3415,6 +3416,8 @@ 
           s2a_expr = Runtime::make_call(Runtime::STRING_TO_INT_ARRAY,
                                         this->location(), 1, this->expr_);
 	}
+      s2a_expr = Expression::make_unsafe_cast(type, s2a_expr,
+					      this->location());
       ret = s2a_expr->get_tree(context);
     }
   else if ((type->is_unsafe_pointer_type()