-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
無駄な代入文を発見する #1
無駄な代入文を発見する #1
Conversation
26e7157
to
2feea5b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
条件分岐への対応が抜けているようです
wastedassign.go
Outdated
s := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA) | ||
|
||
for _, sf := range s.SrcFuncs { | ||
for _, local := range sf.Locals { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naiveモードでビルドしないと厳しくないですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buildssaをforkしてforkしたrepositoryでNaiveモードに変更しています🙏
は
のパターンであっていますか…?(↑直します |
そうですね! |
@@ -0,0 +1,45 @@ | |||
name: test_and_lint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub Actionsで自動でチェックするのいいですね!
reviewdog というツールを使って自動で指摘がある箇所にコメントをつけられるツールもあるので導入してみるとより便利になります
http://haya14busa.com/reviewdog/
あっ、と言うか内容被っちゃってたんですね…(今気がついた |
wastedassign.go
Outdated
if noNextSuccs { | ||
return noUseUntilReturn | ||
} else { | ||
return notWasted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
いい指摘!
test caseを少しいじって package a
func f() {
useOutOfIf := 0 // want "wasted assignment"
if false {
useOutOfIf = 10 // want "reassigned, but never used afterwards"
useOutOfIf = 10 // want "reassigned, but never used afterwards" // <= added
return
}
useOutOfIf = 12
println(useOutOfIf)
return
} のようにすると
のような形でテストが落ちるのですが、これは想定通りですか? |
@110y san
テストケースは正しくはこうなります!
と言った使い分けになっています が、どちらにしろ追加していただいた部分でエラーが出るのは間違っていたので修正しました🙇♂️ |
close後に後出しですみません
(報告用のwantを正しく修正できてないですがよろしくお願いします) func p(x int) int {
return x + 1
}
func f(param int) int {
useOutOfIf := 0
ret := 0
if false {
useOutOfIf = 10 // want "wasted assignment"
useOutOfIf = 10 // want "reassigned, but never used afterwards"
return 0
} else if param == 100 {
ret = useOutOfIf
} else if param == 200 {
useOutOfIf = 100
useOutOfIf = 100
useOutOfIf = p(useOutOfIf)
useOutOfIf += 200
} else {
ret := 100
}
useOutOfIf = 12
println(useOutOfIf)
useOutOfIf = 192 // want "reassigned, but never used afterwards"
useOutOfIf += 100
useOutOfIf += 200
return ret
} |
コメントありがとうございます!
はwastedassignが出力しているエラーではないです(goが出している物)(else句のscopeにretを なのでそもそもtestcaseがgoのコード的によくないです なので正しいtestcaseは(ついでにwantも付与して)こうなると思います
これなら通ります
これに関してですが上のテストケースで"reassigned, but never used afterwards"がちゃんと出力されると思います 長くなりましたが、以上から総じてこのtestcaseは正しく動作している気がします🙏 |
@gasugesu 僕としては上のテストケースだと
が怪しい感じを感じ取っています(returnでしか使ってないしwastedではあるが…と言った感じ |
Oh...
|
大きく分けて
という問題だと思っていて 両方使用しているとみなすべきな気がしてきましたね… 前者は関数からの結果をreturnするというのは明らかに存在するケースですし、後者も色んなスコープで色んな変数に同じ値を定義する際など使用することがありそうです issueに立てておきます!ありがとうございます🙏 |
以下に対して警告を行う
その他
レビュー頂きたい事
自分ではエッジケースが思い付かず、かっっっなりのシンプルな実装になってしまいました何かこの実装で引っかからない特殊なパターンなどありましたら教えていただきたいです🙇♂️