Patchwork [gccgo] A type assertion with nil does not succeed

login
register
mail settings
Submitter Ian Taylor
Date June 30, 2010, 9:32 p.m.
Message ID <mcrzkycyzo4.fsf@google.com>
Download mbox | patch
Permalink /patch/57455/
State New
Headers show

Comments

Ian Taylor - June 30, 2010, 9:32 p.m.
When doing a type assertion such as
    if v, ok := x.(t); ok { }
where x is nil, the type assertion is not considered to succeed.  This
is true even though v := x.(t) does not cause a panic.  This patch
implements that for gccgo.  Committed to gccgo branch.

Ian

Patch

diff -r 509de793fde1 libgo/runtime/go-convert-interface.c
--- a/libgo/runtime/go-convert-interface.c	Wed Jun 30 14:07:44 2010 -0700
+++ b/libgo/runtime/go-convert-interface.c	Wed Jun 30 14:29:05 2010 -0700
@@ -35,7 +35,7 @@ 
   if (rhs == NULL)
     {
       if (success != NULL)
-	*success = 1;
+	*success = 0;
       return NULL;
     }