diff mbox

Go patch committed: comma-ok assignments used untyped bool

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

Commit Message

Ian Lance Taylor Aug. 11, 2014, 7:27 p.m. UTC
The Go language was changed slightly so that comma-ok assignments now
return the ok value as an untyped boolean value rather than as the named
type "bool".  The effect of this is that programs can use an existing
variable of a boolean type that is not actually "bool".  This patch by
Chris Manghane implements this for gccgo.  This requires updating one
test in the testsuite.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline (I goofed slightly and
made two separate svn commits).

Ian
diff mbox

Patch

diff -r 015c9aa9e4a7 go/runtime.cc
--- a/go/runtime.cc	Sun Aug 10 10:07:25 2014 -0700
+++ b/go/runtime.cc	Mon Aug 11 12:23:24 2014 -0700
@@ -24,7 +24,7 @@ 
 {
   // General indicator that value is not used.
   RFT_VOID,
-  // Go type bool, C type _Bool.
+  // Go untyped bool, C type _Bool.
   RFT_BOOL,
   // Go type *bool, C type _Bool*.
   RFT_BOOLPTR,
@@ -93,7 +93,7 @@ 
 	  go_unreachable();
 
 	case RFT_BOOL:
-	  t = Type::lookup_bool_type();
+	  t = Type::make_boolean_type();
 	  break;
 
 	case RFT_BOOLPTR:
diff -r 015c9aa9e4a7 go/statements.cc
--- a/go/statements.cc	Sun Aug 10 10:07:25 2014 -0700
+++ b/go/statements.cc	Mon Aug 11 12:23:24 2014 -0700
@@ -1150,7 +1150,10 @@ 
 
   // var present_temp bool
   Temporary_statement* present_temp =
-    Statement::make_temporary(Type::lookup_bool_type(), NULL, loc);
+    Statement::make_temporary((this->present_->type()->is_sink_type())
+			      ? Type::make_boolean_type()
+			      : this->present_->type(),
+			      NULL, loc);
   b->add_statement(present_temp);
 
   // present_temp = mapaccess2(DESCRIPTOR, MAP, &key_temp, &val_temp)
@@ -1163,7 +1166,6 @@ 
   Expression* a4 = Expression::make_unary(OPERATOR_AND, ref, loc);
   Expression* call = Runtime::make_call(Runtime::MAPACCESS2, loc, 4,
 					a1, a2, a3, a4);
-
   ref = Expression::make_temporary_reference(present_temp, loc);
   ref->set_is_lvalue();
   Statement* s = Statement::make_assignment(ref, call, loc);
@@ -1426,7 +1428,10 @@ 
 
   // var closed_temp bool
   Temporary_statement* closed_temp =
-    Statement::make_temporary(Type::lookup_bool_type(), NULL, loc);
+    Statement::make_temporary((this->closed_->type()->is_sink_type())
+			      ? Type::make_boolean_type()
+			      : this->closed_->type(),
+			      NULL, loc);
   b->add_statement(closed_temp);
 
   // closed_temp = chanrecv2(type, channel, &val_temp)
Index: test/named1.go
===================================================================
--- test/named1.go	(revision 213455)
+++ test/named1.go	(working copy)
@@ -41,21 +41,21 @@  func main() {
 	asBool(1 != 2) // ok now
 	asBool(i < j)  // ok now
 
-	_, b = m[2] // ERROR "cannot .* bool.*type Bool"
+	_, b = m[2]
 
 	var inter interface{}
-	_, b = inter.(Map) // ERROR "cannot .* bool.*type Bool"
+	_, b = inter.(Map)
 	_ = b
 
 	var minter interface {
 		M()
 	}
-	_, b = minter.(Map) // ERROR "cannot .* bool.*type Bool"
+	_, b = minter.(Map)
 	_ = b
 
 	_, bb := <-c
 	asBool(bb) // ERROR "cannot use.*type bool.*as type Bool"
-	_, b = <-c // ERROR "cannot .* bool.*type Bool"
+	_, b = <-c
 	_ = b
 
 	asString(String(slice)) // ok