]> Cypherpunks repositories - gostls13.git/commitdiff
make string(array) take []byte only (and thus *[10]byte but not [10]byte)
authorRuss Cox <rsc@golang.org>
Fri, 17 Apr 2009 06:07:30 +0000 (23:07 -0700)
committerRuss Cox <rsc@golang.org>
Fri, 17 Apr 2009 06:07:30 +0000 (23:07 -0700)
R=ken
OCL=27581
CL=27585

src/cmd/gc/walk.c

index 1fa07dec03b57205ab6dc5d11531a206ccf6e8d0..f64ada8a48356c9b75583c5f1ed6af36e96a72c2 100644 (file)
@@ -1230,8 +1230,9 @@ walkconv(Node *n)
                        indir(n, stringop(n, Erv));
                        return;
                }
-               if(et == TARRAY)
-               if(istype(l->type->type, TUINT8)) {
+               // can convert []byte and *[10]byte
+               if((isptr[et] && isfixedarray(l->type->type) && istype(l->type->type->type, TUINT8))
+               || (isslice(l->type) && istype(l->type->type, TUINT8))) {
                        n->op = OARRAY;
                        indir(n, stringop(n, Erv));
                        return;
@@ -1267,6 +1268,9 @@ walkconv(Node *n)
        }
 
 bad:
+       if(n->diag)
+               return;
+       n->diag = 1;
        if(l->type != T)
                yyerror("invalid conversion: %T to %T", l->type, t);
        else
@@ -2204,8 +2208,6 @@ stringop(Node *n, int top)
        case OARRAY:
                // arraystring([]byte) string;
                r = n->left;
-               if(isfixedarray(r->type))
-                       r = nod(OADDR, r, N);
                on = syslook("arraystring", 0);
                r = nod(OCALL, on, r);
                break;