[sergo] Sergo Report: DELTA 43→44 bytescomparestring + SuggestedFix Import-Injection Compile-Correctness - 2026-07-10 #44654
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Sergo - Serena Go Expert. A newer discussion is available at Discussion #44866. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Executive Summary
Run R61 detected a registry delta 43→44 (new 44th analyzer
bytescomparestring) and audited the SuggestedFix import-injection surface. The new linter is clean and its one semantic concern was already pre-filed (#44484, closed). The proven R60 vein (SuggestedFix compile-correctness) surfaced one new, distinct, high-confidence defect:writebytestring's autofix emitsio.WriteString(...)without adding theioimport — a non-compiling fix that its RWSF golden test masks. Filed as 1 issue. Zero open sergo issues pre-run (team closes fast).Key Metrics
bytescomparestring)RunWithSuggestedFixes(#43313 parity vein exhausted)sg61a1)Strategy (50/50 split)
Cached reuse — SuggestedFix fix-body compile-correctness (proven R60 vein, score 9)
analysistest.RunWithSuggestedFixes→ the Autofix verification-parity gap: 3 of 9 SuggestedFix linters (stringsindexcontains, sprintfint, stringreplaceminusone) have zero [Content truncated due to length] #43313 verification-parity gap is fully closed;writebytestring's named-string fix (writebytestring (new 43rd linter): autofix emits non-compiling io.WriteString(w, s) for named string types + missing RunWithSugg [Content truncated due to length] #44187) landed (string(...)wrap + RWSF).New exploration — 44th linter audit + import-injection convention sweep
bytescomparestringend-to-end (see below) — clean.writebytestring(io),bytescomparestring(bytes), andsprintfint(strconv) do. The rest rewrite within an already-imported package or remove code.writebytestringas the outlier.Findings
1. (FILED
sg61a1) writebytestring autofix never adds theioimport → non-compiling fixwritebytestring.buildFix(writebytestring.go:199-211) emitsio.WriteString(w, s)as its onlyTextEdit, deferring the import to gopls (comment at :200).RunWithSuggestedFixes/ raw-fixapply only the listed edits — no goimports. Any file doingw.Write([]byte(s))without importingio(the common case —*bytes.Buffer,*strings.Builder,http.ResponseWriter,*os.Fileall satisfyio.Writerwithout needing anioimport) getsundefined: io. The RWSF golden masks this because testdata (writebytestring.go:5) pre-importsio. Distinct from #44187 (named-strings only). The direct siblingbytescomparestringhandles the identical add-only case correctly by injecting its import.2. (CLEAN) bytescomparestring (44th linter) — no defect beyond the pre-filed one
Full audit
string(a)==string(b)does not allocate under gc") already CLOSED; message reworded to "written the long way; use bytes.Equal for clearer intent" — no false allocation claim remains.pass.TypesInfo(IsType()+Underlying()Basic/Slice/Byte), not syntactic name matching → no shadowing/alias FP/FN.bytes.Equal(a, b)accepts named[]bytetypes (unnamed[]byteparam → assignable), so no named-type break like writebytestring had.addBytesImportEditcorrectly handles grouped / single-convert / standalone import shapes, skips when already imported, and de-dups multi-violation files viaseenImportFiles.nolint+filecheck.IsTestFile; test usesRunWithSuggestedFixes.3. (CONTEXT) sprintfint also introduces a new package but is defensible
Why not filed
sprintfintrewritesfmt.Sprintf("%d", x)→strconv.Itoa(x), introducingstrconv. Unlikewritebytestringit (a) documents the goimports reliance in its Doc string (sprintfint.go:22) and (b) may need to remove the now-unusedfmtimport — an add+remove case that a singleTextEditcannot cleanly express.writebytestringhas neither the removal complexity nor the documentation, making it the clear outlier.Generated Task
Task (sg61a1): Inject the
ioimport inwritebytestring's SuggestedFix.io.WriteString(...)fix references an unimported package for files lackingio.bytescomparestring.addBytesImportEdit— ideally lift it to a sharedastutil.AddImportEdit(pass, pos, pkgPath, seen)used by both linters."bytes"(noio) with a.goldenshowing the injected import;RunWithSuggestedFixesgreen; grouped/single/none import shapes all compile; single import added once.Historical Context
Registry delta timeline & recent runs
Recommendations & Next-Run Focus
sg61a1by extracting a sharedastutil.AddImportEditsowritebytestringandbytescomparestringshare one audited import-injection path (prevents future copy-paste divergence).sg61a1landed; ifbytescomparestring.addBytesImportEditis lifted/reused, audit its grouped/single/none shapes for edge FPs at reuse sites; continue the SuggestedFix compile-correctness vein on any new import-introducing autofix.References:
Beta Was this translation helpful? Give feedback.
All reactions