]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: recognize !typedbool is typed
authorMatthew Dempsky <mdempsky@google.com>
Thu, 7 Jan 2016 11:06:49 +0000 (03:06 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 7 Jan 2016 21:43:47 +0000 (21:43 +0000)
commit27691fa46735f642b7580d92b80bbf35dc40db97
treed00865b95625469022b56a867189d3f71835cad0
parent3f22adecc7698cd55452d61964aa74e3c4cd16de
cmd/compile: recognize !typedbool is typed

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>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue13821b.go