Unreviewed changes
3 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: go/analysis/passes/modernize/stringsseq.go
Insertions: 18, Deletions: 18.
@@ -116,24 +116,24 @@
continue
}
- if obj := typeutil.Callee(info, call); obj != nil {
- switch obj {
- case stringsSplit, stringsFields, bytesSplit, bytesFields:
- oldFnName := obj.Name()
- seqFnName := fmt.Sprintf("%sSeq", oldFnName)
- pass.Report(analysis.Diagnostic{
- Pos: sel.Pos(),
- End: sel.End(),
- Message: fmt.Sprintf("Ranging over %s is more efficient", seqFnName),
- SuggestedFixes: []analysis.SuggestedFix{{
- Message: fmt.Sprintf("Replace %s with %s", oldFnName, seqFnName),
- TextEdits: append(edits, analysis.TextEdit{
- Pos: sel.Sel.Pos(),
- End: sel.Sel.End(),
- NewText: []byte(seqFnName)}),
- }},
- })
- }
+ switch obj := typeutil.Callee(info, call); obj {
+ case nil:
+ // a conversion, not a call
+ case stringsSplit, stringsFields, bytesSplit, bytesFields:
+ oldFnName := obj.Name()
+ seqFnName := fmt.Sprintf("%sSeq", oldFnName)
+ pass.Report(analysis.Diagnostic{
+ Pos: sel.Pos(),
+ End: sel.End(),
+ Message: fmt.Sprintf("Ranging over %s is more efficient", seqFnName),
+ SuggestedFixes: []analysis.SuggestedFix{{
+ Message: fmt.Sprintf("Replace %s with %s", oldFnName, seqFnName),
+ TextEdits: append(edits, analysis.TextEdit{
+ Pos: sel.Sel.Pos(),
+ End: sel.Sel.End(),
+ NewText: []byte(seqFnName)}),
+ }},
+ })
}
}
}
```
Change information
Commit message:
go/analysis/passes/modernize: fix stringsseq panic
The stringsseq modernizer matches the call operand
of a range statement against strings.Split,
strings.Fields, bytes.Split, or bytes.Fields. If the
call operand is a conversion, typeutil.Callee(call)
will return nil. If the current package does not import
"bytes", the index.Object for bytes.Fields and bytes.Split
will also be nil, so it will match one of these cases and
create a nil panic on obj.Name().
Add a switch case for nil so that we don't enter the
wrong case when the CallExpr is a conversion.
Fixes golang/go#80554
Change-Id: Ie4608a4103ca0d820cdef7450a8612a53a2e0ed9
Files:
- M go/analysis/passes/modernize/modernize_test.go
- M go/analysis/passes/modernize/stringsseq.go
- A go/analysis/passes/modernize/testdata/src/splitseq/conv/nobytes.go
Change size: S
Delta: 3 files changed, 17 insertions(+), 1 deletion(-)
Branch: refs/heads/master