mirror of
https://github.com/golang/go
synced 2024-11-18 01:24:49 -07:00
27691fa467
Adding the evconst(n) call for OANDAND and OOROR in golang.org/cl/18262 was originally just to parallel the above iscmp branch, but upon further inspection it seemed odd that removing it caused test/fixedbugs/issue6671.go's var b mybool // ... b = bool(true) && true // ERROR "cannot use" to start failing (i.e., by not emitting the expected "cannot use" error). The problem is that evconst(n)'s settrue and setfalse paths always reset n.Type to idealbool, even for logical operators where n.Type should preserve the operand type. Adding the evconst(n) call for OANDAND/OOROR inadvertantly worked around this by turning the later evconst(n) call at line 2167 into a noop, so the "n.Type = t" assignment at line 739 would preserve the operand type. However, that means evconst(n) was still clobbering n.Type for ONOT, so declarations like: const _ bool = !mybool(true) were erroneously accepted. Update #13821. Change-Id: I18e37287f05398fdaeecc0f0d23984e244f025da Reviewed-on: https://go-review.googlesource.com/18362 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
25 lines
728 B
Go
25 lines
728 B
Go
// 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"
|
|
|
|
var x8 = b && !B2(true) // ERROR "mismatched types B and B2"
|