]> Cypherpunks repositories - gostls13.git/commitdiff
named string type bugs
authorRuss Cox <rsc@golang.org>
Mon, 27 Jul 2009 22:16:28 +0000 (15:16 -0700)
committerRuss Cox <rsc@golang.org>
Mon, 27 Jul 2009 22:16:28 +0000 (15:16 -0700)
R=ken
OCL=32244
CL=32244

src/cmd/gc/walk.c
test/fixedbugs/bug173.go [new file with mode: 0644]

index 047ae099288c451accd58d66e18c2b5d4c7e00b8..31db1e7b4c2febb426bb99942dcd5d35fd19da1d 100644 (file)
@@ -2715,7 +2715,9 @@ stringop(Node *n, int top, NodeList **init)
                break;
 
        case OSLICE:
-               args = list1(n->left);
+               r = nod(OCONV, n->left, N);
+               r->type = types[TSTRING];
+               args = list1(r);
 
                // sys_slicestring(s, lb, hb)
                r = nod(OCONV, n->right->left, N);
@@ -2733,7 +2735,10 @@ stringop(Node *n, int top, NodeList **init)
 
        case OINDEX:
                // sys_indexstring(s, i)
-               args = list1(n->left);
+               r = nod(OCONV, n->left, N);
+               r->type = types[TSTRING];
+               args = list1(r);
+
                r = nod(OCONV, n->right, N);
                r->type = types[TINT];
                args = list(args, r);
@@ -2753,9 +2758,10 @@ stringop(Node *n, int top, NodeList **init)
                break;
 
        case OARRAY:
-               r = n->left;
                // arraystring([]byte) string;
                on = syslook("arraystring", 0);
+               r = n->left;
+
                if(r->type != T && r->type->type != T) {
                        if(istype(r->type->type, TINT) || istype(r->type->type->type, TINT)) {
                                // arraystring([]byte) string;
@@ -4081,7 +4087,7 @@ strng:
        tempname(ohk, types[TINT]);
 
        ha = nod(OXXX, N, N);           // hidden string
-       tempname(ha, t);
+       tempname(ha, types[TSTRING]);
 
        hv = N;
        if(v != N) {
@@ -4096,7 +4102,9 @@ strng:
        }
 
        // ha = s
-       a = nod(OAS, ha, m);
+       a = nod(OCONV, m, N);
+       a->type = ha->type;
+       a = nod(OAS, ha, a);
        init = list(init, a);
 
        // ohk = 0
diff --git a/test/fixedbugs/bug173.go b/test/fixedbugs/bug173.go
new file mode 100644 (file)
index 0000000..a9e07e9
--- /dev/null
@@ -0,0 +1,21 @@
+// $G $D/$F.go || echo BUG: bug173
+
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// these used to fail because the runtime
+// functions that get called to implement them
+// expected string, not T.
+
+package main
+
+type T string
+func main() {
+       var t T = "hello";
+       println(t[0:4], t[4]);
+       for i, x := range t {
+       }
+       for i := range t {
+       }
+}