diff mbox

Go patch committed: Don't crash on type switch of nil

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

Commit Message

Ian Lance Taylor Feb. 24, 2011, 3:53 a.m. UTC
This patch to the Go frontend avoids a crash when doing a type switch of
nil.  This is not a useful construct, but the compiler shouldn't crash.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian
diff mbox

Patch

diff -r 3adbd7c1f51a go/statements.cc
--- a/go/statements.cc	Wed Feb 23 19:36:14 2011 -0800
+++ b/go/statements.cc	Wed Feb 23 19:49:17 2011 -0800
@@ -3905,10 +3905,13 @@ 
     {
       // Doing a type switch on a non-interface type.  Should we issue
       // a warning for this case?
-      // descriptor_temp = DESCRIPTOR
       Expression* lhs = Expression::make_temporary_reference(descriptor_temp,
 							     loc);
-      Expression* rhs = Expression::make_type_descriptor(val_type, loc);
+      Expression* rhs;
+      if (val_type->is_nil_type())
+	rhs = Expression::make_nil(loc);
+      else
+	rhs = Expression::make_type_descriptor(val_type, loc);
       Statement* s = Statement::make_assignment(lhs, rhs, loc);
       b->add_statement(s);
     }