Skip to content

Commit a95c3b5

Browse files
committed
staticcheck: don't crash when checking dot-imported constants in bitwise ops
Closes gh-719 (cherry picked from commit f5dad99)
1 parent 60ae5a6 commit a95c3b5

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

staticcheck/lint.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,10 @@ func CheckSillyBitwiseOps(pass *analysis.Pass) (interface{}, error) {
27112711
if !ok {
27122712
return
27132713
}
2714+
if obj.Pkg() != pass.Pkg {
2715+
// identifier was dot-imported
2716+
return
2717+
}
27142718
if v, _ := constant.Int64Val(obj.Val()); v != 0 {
27152719
return
27162720
}

staticcheck/lint_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestAll(t *testing.T) {
5555
"SA4013": {{Dir: "CheckDoubleNegation"}},
5656
"SA4014": {{Dir: "CheckRepeatedIfElse"}},
5757
"SA4015": {{Dir: "CheckMathInt"}},
58-
"SA4016": {{Dir: "CheckSillyBitwiseOps"}, {Dir: "CheckSillyBitwiseOps_shadowedIota"}},
58+
"SA4016": {{Dir: "CheckSillyBitwiseOps"}, {Dir: "CheckSillyBitwiseOps_shadowedIota"}, {Dir: "CheckSillyBitwiseOps_dotImport"}},
5959
"SA4017": {{Dir: "CheckPureFunctions"}},
6060
"SA4018": {{Dir: "CheckSelfAssignment"}},
6161
"SA4019": {{Dir: "CheckDuplicateBuildConstraints"}},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package foo
2+
3+
const X = 0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package foo_test
2+
3+
import . "CheckSillyBitwiseOps_dotImport"
4+
5+
var _ = 1 | X

0 commit comments

Comments
 (0)