Skip to content

Commit

Permalink
Merge pull request #30 from sanposhiho/fix/error-message
Browse files Browse the repository at this point in the history
Fix: fix error message. reassigned to assigned
  • Loading branch information
sanposhiho authored May 5, 2021
2 parents e1c12f5 + db6d5b1 commit e5b432c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
45 changes: 31 additions & 14 deletions testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ func noUseParams(params string) int {

func f(param int) int {
println(param)
useOutOfIf := 1212121 // want "reassigned, but reassigned without using the value"
useOutOfIf := 1212121 // want "assigned, but reassigned without using the value"
ret := 0
if false {
useOutOfIf = 200 // want "reassigned, but never used afterwards"
useOutOfIf = 200 // want "assigned, but never used afterwards"
return 0
} else if param == 100 {
useOutOfIf = 100 // want "reassigned, but reassigned without using the value"
useOutOfIf = 100 // want "assigned, but reassigned without using the value"
useOutOfIf = 201
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200 // want "reassigned, but reassigned without using the value"
useOutOfIf += 200 // want "assigned, but reassigned without using the value"
} else {
useOutOfIf = 100
useOutOfIf += 100
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200 // want "reassigned, but reassigned without using the value"
useOutOfIf += 200 // want "assigned, but reassigned without using the value"
}

if false {
useOutOfIf = 200 // want "reassigned, but never used afterwards"
useOutOfIf = 200 // want "assigned, but never used afterwards"
return 0
} else if param == 200 {
useOutOfIf = 100 // want "reassigned, but reassigned without using the value"
useOutOfIf = 100 // want "assigned, but reassigned without using the value"
useOutOfIf = 201
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200
Expand All @@ -63,7 +63,7 @@ func f(param int) int {
println(useOutOfIf)
useOutOfIf = 192
useOutOfIf += 100
useOutOfIf += 200 // want "reassigned, but never used afterwards"
useOutOfIf += 200 // want "assigned, but never used afterwards"
return ret
}

Expand All @@ -72,7 +72,7 @@ func checkLoopTest() int {
noUse := 1111
println(noUse)

noUse = 1111 // want "reassigned, but never used afterwards"
noUse = 1111 // want "assigned, but never used afterwards"
for {
if hoge == 14 {
break
Expand All @@ -87,29 +87,29 @@ func r(param int) int {
useOutOfIf := 1212121
ret := 0
if false {
useOutOfIf = 200 // want "reassigned, but never used afterwards"
useOutOfIf = 200 // want "assigned, but never used afterwards"
return 0
} else if param == 100 {
ret = useOutOfIf
} else if param == 200 {
useOutOfIf = 100 // want "reassigned, but reassigned without using the value"
useOutOfIf = 100 // want "assigned, but reassigned without using the value"
useOutOfIf = 100
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200 // want "reassigned, but reassigned without using the value"
useOutOfIf += 200 // want "assigned, but reassigned without using the value"
}
useOutOfIf = 12
println(useOutOfIf)
useOutOfIf = 192
useOutOfIf += 100
useOutOfIf += 200 // want "reassigned, but never used afterwards"
useOutOfIf += 200 // want "assigned, but never used afterwards"
return ret
}

func mugen() {
var i int
var hoge int
for {
hoge = 5 // want "reassigned, but reassigned without using the value"
hoge = 5 // want "assigned, but reassigned without using the value"
// break
}

Expand Down Expand Up @@ -153,3 +153,20 @@ func reassignInsideLoop2() {
}
println(x)
}

func foo() error {
var flag bool
var n int

switch n {
case 10:
flag = false
case 11:
flag = true
default:
return nil
}

println(flag)
return nil
}
6 changes: 3 additions & 3 deletions wastedassign.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,17 @@ func run(pass *analysis.Pass) (interface{}, error) {
type wastedReason string

const (
noUseUntilReturn wastedReason = "reassigned, but never used afterwards"
noUseUntilReturn wastedReason = "assigned, but never used afterwards"
reassignedSoon wastedReason = "wasted assignment"
notWasted wastedReason = ""
)

func (wr wastedReason) String() string {
switch wr {
case noUseUntilReturn:
return "reassigned, but never used afterwards"
return "assigned, but never used afterwards"
case reassignedSoon:
return "reassigned, but reassigned without using the value"
return "assigned, but reassigned without using the value"
case notWasted:
return ""
default:
Expand Down

0 comments on commit e5b432c

Please sign in to comment.