• Daniel Martí's avatar
    cmd/vet: skip self-assigns with side effects · 320b0cdd
    Daniel Martí authored
    The existing logic for whether the left and right parts of an assignment
    were equal only checked that the gofmt representation of the two was
    equal. This only checks that the ASTs were equal.
    
    However, that method is flawed. For example, if either of the
    expressions contains a function call, the expressions may actually be
    different even if their ASTs are the same. An obvious case is a func
    call to math/rand to get a random integer, such as the one added in the
    test.
    
    If either of the expressions may have side effects, simply skip the
    check. Reuse the logic from bool.go's hasSideEffects.
    
    Fixes #22174.
    
    Change-Id: Ied7f7543dc2bb8852e817230756c6d23bc801d90
    Reviewed-on: https://go-review.googlesource.com/69116
    Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarRob Pike <r@golang.org>
    320b0cdd
Name
Last commit
Last update
..
asm Loading commit data...
buildtag Loading commit data...
cgo Loading commit data...
divergent Loading commit data...
incomplete Loading commit data...
tagtest Loading commit data...
testingpkg Loading commit data...
asm8.s Loading commit data...
assign.go Loading commit data...
atomic.go Loading commit data...
bool.go Loading commit data...
composite.go Loading commit data...
copylock.go Loading commit data...
copylock_func.go Loading commit data...
copylock_range.go Loading commit data...
deadcode.go Loading commit data...
httpresponse.go Loading commit data...
lostcancel.go Loading commit data...
method.go Loading commit data...
nilfunc.go Loading commit data...
print.go Loading commit data...
rangeloop.go Loading commit data...
shadow.go Loading commit data...
shift.go Loading commit data...
structtag.go Loading commit data...
unsafeptr.go Loading commit data...
unused.go Loading commit data...