]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix string comparisons for new bool rules
authorAnthony Martin <ality@pbrane.org>
Wed, 29 Feb 2012 21:55:50 +0000 (13:55 -0800)
committerAnthony Martin <ality@pbrane.org>
Wed, 29 Feb 2012 21:55:50 +0000 (13:55 -0800)
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
test/fixedbugs/bug425.go [new file with mode: 0644]

index 9bd0a699cb72a4256dd2bf41868715a6208abe59..74298e1266c5e3a9356969ac05f2a37ce20f4454 100644 (file)
@@ -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 (file)
index 0000000..5546bd9
--- /dev/null
@@ -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")
+}