Skip to content

Give stringbytesroundtrip.isExactString its own exactness logic - #54722

Open
pelikhan with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-stringbytesroundtrip-no-op-alias
Open

Give stringbytesroundtrip.isExactString its own exactness logic#54722
pelikhan with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-stringbytesroundtrip-no-op-alias

Conversation

Copilot AI commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

stringbytesroundtrip.isExactString was a no-op alias of isStringType, producing correct results only because callers happened to pass raw types (*types.Named fails the *types.Basic assertion) while the gating checks passed .Underlying()-resolved types. Nothing in the name, signature, or body enforced that discipline — the same missing distinction that produced the non-compiling autofix in the sibling writebytestring linter (sg60a1).

Changes

  • isExactString implemented independently — explicitly rejects *types.Named and checks t.Underlying(), so it no longer depends on which type snapshot the caller passes:

    func isExactString(t types.Type) bool {
        if _, named := t.(*types.Named); named {
            return false
        }
        return isStringType(t.Underlying())
    }
  • Documented the contract on both helpersisExactString expects the raw type and explains why the predeclared/named split matters (only predeclared string allows removing both conversions); isStringType notes it is given an already-resolved underlying type.

  • Testdata coverage — new badMixedNamedTypes fixture exercises both round-trip branches with a named outer conversion (myString([]byte(s))), a named argument (string([]byte(ms))), and an alias of the predeclared string (aliasString([]byte(as)), which must report the "both conversions can be removed" variant).

No diagnostic output changes for existing inputs; this closes the latent gap so a future SuggestedFix on the redundant branch can't silently reintroduce the sg60a1 bug class.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix no-op alias for isExactString in stringbytesroundtrip Give stringbytesroundtrip.isExactString its own exactness logic Aug 22, 2026
Copilot AI requested a review from pelikhan August 22, 2026 04:30
@pelikhan
pelikhan marked this pull request as ready for review August 22, 2026 06:09
Copilot AI balanced review requested due to automatic review settings August 22, 2026 06:09
@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Lean already. Ship.

Generated by Ponytail Reviewer for #54722

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories (29 additions across 2 files).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-08-22T06:12:00Z
review_event: COMMENT
top_themes:
  - no actionable issues found in changed lines
files_reviewed:
  - pkg/linters/stringbytesroundtrip/stringbytesroundtrip.go
  - pkg/linters/stringbytesroundtrip/testdata/src/stringbytesroundtrip/stringbytesroundtrip.go
comment_count: 0

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 3.12 AIC · ⌖ 6.74 AIC · ⊞ 7K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

No actionable correctness, performance, or maintainability issues stood out in the changed lines.

Reviewed focus

Checked the exact-string type discrimination change and the new named/alias test coverage for changed-line regressions. The implementation now makes the raw-type vs underlying-type distinction explicit, and the added fixtures cover the important behavioral split between named string types and aliases.

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 3.12 AIC · ⌖ 6.74 AIC · ⊞ 7K
Comment /review to run again

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Separates exact predeclared-string detection from underlying string-type detection.

Changes:

  • Implements dedicated isExactString logic and documents helper contracts.
  • Adds named-type and predeclared-alias fixtures.
Show a summary per file
File Description
pkg/linters/stringbytesroundtrip/stringbytesroundtrip.go Adds exactness detection logic.
pkg/linters/stringbytesroundtrip/testdata/src/stringbytesroundtrip/stringbytesroundtrip.go Adds mixed named and alias coverage.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +152 to +155
if _, named := t.(*types.Named); named {
return false
}
return isStringType(t.Underlying())

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /codebase-design and /diagnosing-bugs — approving with one minor doc comment suggestion.

📋 Key Themes & Highlights

Positive Highlights

  • ✅ Root cause properly addressed: isExactString now owns its own type-resolution logic instead of silently relying on caller discipline.
  • ✅ The *types.Named early-return + t.Underlying() pattern is idiomatic and correctly handles type aliases (= string) because they are not *types.Named.
  • ✅ Testdata fixture covers all three meaningful branches: named outer type, named argument, and aliased predeclared string.
  • ✅ PR description precisely describes the original defect, which is helpful for future archaeology.

Minor

  • The isStringType doc comment says "so this also matches named string types" — slightly misleading since the body only matches *types.Basic. One small clarification (see inline comment) would remove the ambiguity.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 24.8 AIC · ⌖ 9.75 AIC · ⊞ 7.6K
Comment /matt to run again

)
}

// isStringType reports whether t is a string basic type. Callers pass an

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] The phrase "so this also matches named string types" in the doc comment is slightly misleading — the body only ever matches *types.Basic. The intent is that callers pass a pre-resolved underlying type (which may originate from a named type), so the comment is about caller convention, not the function's own behaviour.

💡 Suggested wording
// isStringType reports whether t is a string basic type. Callers must pass an
// already-.Underlying()-resolved type; the function does not resolve named types
// itself.

This avoids implying the function handles *types.Named directly.

@copilot please address this.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is correct. isExactString now properly distinguishes between the predeclared string type and named string types (type MyString string) by checking for *types.Named before calling isStringType. Type aliases (type aliasString = string) are not represented as *types.Named in go/types, so they correctly pass through and are treated as exact strings — both conversions can be removed. The added test cases validate all three paths.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 14.8 AIC · ⌖ 8.97 AIC · ⊞ 6.2K

@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: bug
  • Risk: low
  • Priority score: 60/100 (impact 30, urgency 10, quality 20)
  • Recommended action: auto_merge
  • CI status: passing

Generated by 🔧 PR Triage Agent · auto · 82.9 AIC · ⌖ 6.65 AIC · ⊞ 8.3K ·

@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

Category: bug | Risk: low | Priority: medium | Score: 58/100
Recommended action: auto_merge

Non-draft, CI green (29 success), 2x APPROVED. Ready to merge.

Automated triage — run 32572524009

Generated by 🔧 PR Triage Agent · auto · 65.4 AIC · ⌖ 6.04 AIC · ⊞ 8.3K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot this PR still needs forward progress before maintainer review.

Run: https://github.com/github/gh-aw/actions/runs/32573431024

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.09 AIC · ⌖ 8.39 AIC · ⊞ 9.5K ·
Comment /souschef to run again

Copilot AI and others added 2 commits August 22, 2026 12:50
…esroundtrip-no-op-alias

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot this PR still needs forward progress before maintainer review.

  • Please address the remaining issues, refresh the branch if possible, and run the pr-finisher skill before handoff....

Addressed in the latest commit.

Review feedback (alias-to-named types): isExactString now resolves aliases with types.Unalias before the basic-type check, so type namedAlias = myString is no longer mistaken for the predeclared string. Added a namedAlias fixture; reverting to the previous *types.Named check makes it fail with "both conversions can be removed" instead of "replace it with namedAlias(na)", so it pins the regression.

Failed checks: both were caused by the branch being stale rather than by the change — origin/main was unresolvable in the CI checkout, so test-impacted-go could not compute a merge-base (unable to determine merge-base from BASE_REF=origin/main) and lint-go-custom fell back to linting every Go file, surfacing ~700 pre-existing findings across pkg/cli and cmd/. Merged origin/main into the branch to fix both.

Commands and outcomes:

  • go test ./pkg/linters/stringbytesroundtrip/... → ok
  • make golint-custom LINTER_FLAGS="... -stringbytesroundtrip -errormessage -errormessage.changed-files=<changed>" (CI-scoped set) → clean, no findings in the changed files
  • make agent-report-progressPre-PR validation passed

No diagnostic output changes for pre-existing inputs.

Copilot AI requested a review from gh-aw-bot August 22, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stringbytesroundtrip: isExactString is a no-op alias of isStringType — latent risk of the sg60a1 (writebytestring) bug class

4 participants