diff mbox

Go patch committed: Don't crash on erroneous type switch

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

Commit Message

Ian Lance Taylor Feb. 22, 2011, 3:01 a.m. UTC
This patch to the Go frontend avoids a segfault in the compiler on an
erroneous type switch.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff mbox

Patch

diff -r 2f6d7684b1e4 go/parse.cc
--- a/go/parse.cc	Mon Feb 21 18:51:55 2011 -0800
+++ b/go/parse.cc	Mon Feb 21 18:57:48 2011 -0800
@@ -3799,11 +3799,14 @@ 
 		  // This must be a TypeSwitchGuard.
 		  switch_val = this->simple_stat(false, true, NULL,
 						 &type_switch);
-		  if (!type_switch.found
-		      && !switch_val->is_error_expression())
+		  if (!type_switch.found)
 		    {
-		      error_at(id_loc, "expected type switch assignment");
-		      switch_val = Expression::make_error(id_loc);
+		      if (switch_val == NULL
+			  || !switch_val->is_error_expression())
+			{
+			  error_at(id_loc, "expected type switch assignment");
+			  switch_val = Expression::make_error(id_loc);
+			}
 		    }
 		}
 	    }