From 564a1f3358c2d4f6d1f04ef5acef4057d4421360 Mon Sep 17 00:00:00 2001 From: Anthony Martin Date: Wed, 29 Feb 2012 13:55:50 -0800 Subject: [PATCH] gc: fix string comparisons for new bool rules The two string comparison optimizations were missing the implicit cast from ideal bool. Fixes #3119. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5696071 --- src/cmd/gc/walk.c | 2 ++ test/fixedbugs/bug425.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/fixedbugs/bug425.go diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c index 9bd0a699cb..74298e1266 100644 --- a/src/cmd/gc/walk.c +++ b/src/cmd/gc/walk.c @@ -1017,6 +1017,7 @@ walkexpr(Node **np, NodeList **init) r = nod(n->etype, nod(OLEN, n->left, N), nod(OLEN, n->right, N)); typecheck(&r, Erv); walkexpr(&r, init); + r->type = n->type; n = r; goto ret; } @@ -1029,6 +1030,7 @@ walkexpr(Node **np, NodeList **init) r = nod(n->etype, nod(OLEN, n->left->left, N), nodintconst(0)); typecheck(&r, Erv); walkexpr(&r, init); + r->type = n->type; n = r; goto ret; } diff --git a/test/fixedbugs/bug425.go b/test/fixedbugs/bug425.go new file mode 100644 index 0000000000..5546bd96ba --- /dev/null +++ b/test/fixedbugs/bug425.go @@ -0,0 +1,17 @@ +// compile + +// Copyright 2012 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. + +// http://code.google.com/p/go/issues/detail?id=3119 + +package main + +import "fmt" + +func main() { + s := "hello" + fmt.Println(s == "") + fmt.Println(s + "world" == "world") +} -- 2.50.0