diff mbox

Go patch committed: Don't permit assigning abstract string to numeric

Message ID mcr1v5almzh.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Dec. 21, 2010, 11:33 p.m. UTC
This patch fixes a bug in the Go frontend: it permitted assigning an
abstract string (or bool) to a variable with numeric type.  Bootstrapped
and ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to
mainline.

Ian
diff mbox

Patch

diff -r 51b5b97197e8 go/types.cc
--- a/go/types.cc	Tue Dec 21 15:18:33 2010 -0800
+++ b/go/types.cc	Tue Dec 21 15:31:03 2010 -0800
@@ -543,15 +543,17 @@ 
 	  || lhs->interface_type() != NULL))
     return true;
 
-  // An untyped constant may be assigned to a numeric type if it is
-  // representable in that type.
-  if (rhs->is_abstract()
+  // An untyped numeric constant may be assigned to a numeric type if
+  // it is representable in that type.
+  if ((rhs->is_abstract()
+       && (rhs->integer_type() != NULL
+	   || rhs->float_type() != NULL
+	   || rhs->complex_type() != NULL))
       && (lhs->integer_type() != NULL
 	  || lhs->float_type() != NULL
 	  || lhs->complex_type() != NULL))
     return true;
 
-
   // Give some better error messages.
   if (reason != NULL && reason->empty())
     {