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

login
register
mail settings
Submitter Ian Taylor
Date Dec. 21, 2010, 11:33 p.m.
Message ID <mcr1v5almzh.fsf@google.com>
Download mbox | patch
Permalink /patch/76345/
State New
Headers show

Comments

Ian Taylor - Dec. 21, 2010, 11:33 p.m.
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

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())
     {