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
- }
- } else
- // non-comparison operators on ideal bools should make them lose their ideal-ness
- if t == idealbool {
- t = Types[TBOOL]
+ evconst(n)
}
if et == TSTRING {
switch n.Op {
case OCONVNOP:
- if n.Left.Op == OLITERAL && n.Type != Types[TBOOL] {
+ if n.Left.Op == OLITERAL {
r := Nod(OXXX, nil, nil)
n.Op = OCONV
n.Orig = r
--- /dev/null
+// compile
+
+// Copyright 2015 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 13821. Compiler rejected "bool(true)" as not a constant.
+
+package p
+
+const (
+ A = true
+ B = bool(A)
+ C = bool(true)
+)
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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 13821. Additional regress tests.
+
+package p
+
+type B bool
+type B2 bool
+
+var b B
+var b2 B2
+var x1 = b && 1 < 2 // x1 has type B, not ideal bool
+var x2 = 1 < 2 && b // x2 has type B, not ideal bool
+var x3 = b && b2 // ERROR "mismatched types B and B2"
+var x4 = x1 && b2 // ERROR "mismatched types B and B2"
+var x5 = x2 && b2 // ERROR "mismatched types B and B2"
+var x6 = b2 && x1 // ERROR "mismatched types B2 and B"
+var x7 = b2 && x2 // ERROR "mismatched types B2 and B"