diff mbox

Go patch committed: Don't crash on switch _ := v.(type)

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

Commit Message

Ian Lance Taylor Feb. 1, 2012, 8:40 p.m. UTC
This patch to the Go compiler avoids crashing on switch _ := v.(type).
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian
diff mbox

Patch

diff -r 6cc0b85ab55c go/parse.cc
--- a/go/parse.cc	Wed Feb 01 11:15:32 2012 -0800
+++ b/go/parse.cc	Wed Feb 01 12:38:57 2012 -0800
@@ -4311,9 +4311,16 @@ 
   Named_object* switch_no = NULL;
   if (!type_switch.name.empty())
     {
-      Variable* switch_var = new Variable(NULL, type_switch.expr, false, false,
-					  false, type_switch.location);
-      switch_no = this->gogo_->add_variable(type_switch.name, switch_var);
+      if (Gogo::is_sink_name(type_switch.name))
+	error_at(type_switch.location,
+		 "no new variables on left side of %<:=%>");
+      else
+	{
+	  Variable* switch_var = new Variable(NULL, type_switch.expr, false,
+					      false, false,
+					      type_switch.location);
+	  switch_no = this->gogo_->add_variable(type_switch.name, switch_var);
+	}
     }
 
   Type_switch_statement* statement =