8000 s1024: don't suggest an invalid fix when Sub is not called on a time.Time by Eljees · Pull Request #1730 · dominikh/go-tools · GitHub
[go: up one dir, main page]

Skip to content

s1024: don't suggest an invalid fix when Sub is not called on a time.Time - #1730

Open
Eljees wants to merge 2 commits into
dominikh:masterfrom
Eljees:fix/756-s1024-invalid-fix
Open

Eljees wants to merge 2 commits into
dominikh:masterfrom
Eljees:fix/756-s1024-invalid-fix

Conversation

@Eljees
@Eljees Eljees commented Aug 6, 2026
Copy link
Copy Markdown

Fixes #756.

S1024 rewrites x.Sub(time.Now()) into time.Until(x), which only compiles when x is itself a time.Time. Sub is reachable in two other shapes, and the fix produces code that does not build in either:

type embedTime struct{ time.Time }

func fnEmbedded(t embedTime) { t.Sub(time.Now()) } // fix: time.Until(t)
func fnPointer(t *time.Time) { t.Sub(time.Now()) } // fix: time.Until(t)

The pointer case is not in the issue, but it has the same cause.

Emitting time.Until(t.Time) for the embedded case would be nicer than dropping the fix, but the embedded field is not always nameable at the use site — it can be unexported and declared in another package — so this keeps the diagnostic and reports it without a fix instead.

The testdata gains both shapes. On the current tree the golden file fails with exactly the two invalid rewrites.

@Eljees
Eljees commented Sep 17, 2026
Copy link
Copy Markdown
Author

Checking in — this has been open since 6 August with no review yet. It's green and mergeable; happy to rebase or add anything you'd like before you take a look.

@dominikh
Copy link
Copy Markdown
Owner

Sorry, but I'm slow to review PRs. Nothing is needed from your side at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S1024: incorrect suggested fix for embedded type

2 participants

0