From 811e59f2fae3755555101e81952b4909b4c15dee Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 27 Jul 2009 15:16:28 -0700 Subject: [PATCH] named string type bugs R=ken OCL=32244 CL=32244 --- src/cmd/gc/walk.c | 18 +++++++++++++----- test/fixedbugs/bug173.go | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 test/fixedbugs/bug173.go diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c index 047ae09928..31db1e7b4c 100644 --- a/src/cmd/gc/walk.c +++ b/src/cmd/gc/walk.c @@ -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 index 0000000000..a9e07e9d93 --- /dev/null +++ b/test/fixedbugs/bug173.go @@ -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 { + } +} -- 2.48.1