refactor: extract shared calleeObject helper in lint cops#3396
Merged
Conversation
Deduplicate callee-object resolution between ConstructorCommandExec and ConstructorNetworkIO by pulling the switch into a single calleeObject helper. Assisted-By: docker/docker-agent
docker-agent
reviewed
Jul 1, 2026
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
This refactoring correctly extracts the duplicated callee-resolution type-switch into a single calleeObject helper. The behaviour is identical to the original code in both callers:
- Nil-safety preserved:
calleeObjectguardsinfo == nilexactly as the oldif p.Info != nilblocks did. BothosExecFuncNameandnetworkIOFuncNameuse the safe comma-ok type assertion (obj.(*types.Func)), so passingnilis well-defined and returns the zero/false pair — no panic risk. - Map-lookup semantics unchanged:
info.Uses[fun.Sel]andinfo.Uses[fun]returnnil(the zero value for thetypes.Objectinterface) on a missing key, which both downstream functions already handle correctly. - Fallthrough paths intact: The
cop.CallTofallback incommandConstructorCalland the twocop.CallTochecks innetworkIOCallare untouched and still reachable. - Type-switch coverage identical: The helper covers exactly the same
*ast.SelectorExprand*ast.Identcases as the original inline blocks, with an explicitdefault: return nilthat is semantically equivalent to not entering the switch.
trungutt
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both
constructor_command_exec.goandconstructor_network_io.gocontained nearly identical type-switch blocks to extract the callee object from a call expression — handling both bare*ast.Identand selector-expression*ast.SelectorExprcases, then resolving the corresponding types.Object from type info. The duplication made each cop harder to read and meant any future fix had to be applied twice.This change extracts that logic into a single
calleeObjecthelper inconstructor_command_exec.goand updatesconstructor_network_io.goto call it, removing around 20 lines of duplicated branching with no change in behaviour.No breaking changes. Both cops produce identical diagnostics before and after.