diff mbox

Go patch committed: Correct type of character expressions

Message ID mcrehuoyjx9.fsf@dhcp-172-18-216-180.mtv.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Jan. 24, 2012, 7:33 p.m. UTC
This patch to the Go compiler corrects the type of expressions involving
untyped character constants.  An expression like 'a' + 1 should take on
the type rune, not the type int.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff mbox

Patch

diff -r cffcfa23a3b4 go/expressions.cc
--- a/go/expressions.cc	Tue Jan 24 09:51:15 2012 -0800
+++ b/go/expressions.cc	Tue Jan 24 11:10:00 2012 -0800
@@ -5556,7 +5556,9 @@ 
 	Expression* ret = NULL;
 	if (left_type != right_type
 	    && left_type != NULL
+	    && !left_type->is_abstract()
 	    && right_type != NULL
+	    && !right_type->is_abstract()
 	    && left_type->base() != right_type->base()
 	    && op != OPERATOR_LSHIFT
 	    && op != OPERATOR_RSHIFT)
@@ -5608,7 +5610,27 @@ 
 		  type = right_type;
 		else
 		  type = left_type;
-		ret = Expression::make_integer(&val, type, location);
+
+		bool is_character = false;
+		if (type == NULL)
+		  {
+		    Type* t = this->left_->type();
+		    if (t->integer_type() != NULL
+			&& t->integer_type()->is_rune())
+		      is_character = true;
+		    else if (op != OPERATOR_LSHIFT && op != OPERATOR_RSHIFT)
+		      {
+			t = this->right_->type();
+			if (t->integer_type() != NULL
+			    && t->integer_type()->is_rune())
+			  is_character = true;
+		      }
+		  }
+
+		if (is_character)
+		  ret = Expression::make_character(&val, type, location);
+		else
+		  ret = Expression::make_integer(&val, type, location);
 	      }
 
 	    mpz_clear(val);
@@ -6252,6 +6274,12 @@ 
 	  return left_type;
 	else if (right_type->float_type() != NULL)
 	  return right_type;
+	else if (left_type->integer_type() != NULL
+		 && left_type->integer_type()->is_rune())
+	  return left_type;
+	else if (right_type->integer_type() != NULL
+		 && right_type->integer_type()->is_rune())
+	  return right_type;
 	else
 	  return left_type;
       }