n->left = l;
n->right = r;
}
+ } else if(n->op == OANDAND || n->op == OOROR) {
+ if(l->type == r->type)
+ t = l->type;
+ else if(l->type == idealbool)
+ t = r->type;
+ else if(r->type == idealbool)
+ t = l->type;
// non-comparison operators on ideal bools should make them lose their ideal-ness
} else if(t == idealbool)
t = types[TBOOL];
}
switch(n->op) {
case OCONVNOP:
- if(n->left->op == OLITERAL) {
+ if(n->left->op == OLITERAL && n->type != types[TBOOL]) {
r = nod(OXXX, N, N);
n->op = OCONV;
n->orig = r;
+++ /dev/null
-// errorcheck
-
-// 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.
-
-package foo
-
-type mybool bool
-
-var x, y = 1, 2
-var _ mybool = x < y && x < y // ERROR "cannot use"
-var _ mybool = x < y || x < y // ERROR "cannot use"
--- /dev/null
+// errorcheck
+
+// Copyright 2014 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.
+
+// Issue 6671: Logical operators should produce untyped bool for untyped operands.
+
+package p
+
+type mybool bool
+
+func _(x, y int) {
+ type mybool bool
+ var b mybool
+ _ = b
+ b = bool(true) // ERROR "cannot use"
+ b = true // permitted as expected
+ b = bool(true) && true // ERROR "cannot use"
+ b = true && true // permitted => && returns an untyped bool
+ b = x < y // permitted => x < y returns an untyped bool
+ b = true && x < y // permitted => result of && returns untyped bool
+ b = x < y && x < y // permitted => result of && returns untyped bool
+ b = x < y || x < y // permitted => result of || returns untyped bool
+ var c bool = true && x < y // permitted => result of && is bool
+ c = false || x < y // permitted => result of || returns untyped bool
+ _ = c
+}