Fix false positive in getReqCall: use types.Identical instead of string matching#79
Open
soh335 wants to merge 1 commit intotimakin:masterfrom
Open
Fix false positive in getReqCall: use types.Identical instead of string matching#79soh335 wants to merge 1 commit intotimakin:masterfrom
soh335 wants to merge 1 commit intotimakin:masterfrom
Conversation
…strings.Contains Replace string-based type matching (strings.Contains on call.Type().String()) with precise type comparison using types.Identical. This eliminates false positives where functions returning types that contain *http.Response as a parameter (e.g., retryablehttp.CheckRetry-style function types) were incorrectly flagged. Changes: - Use types.Identical for single return values and *types.Tuple element checking for multiple return values - Remove strings import (no longer needed) - Add test case for function type return values (function_type.go) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Closes #71
Problem
getReqCallcurrently usesstrings.Contains(call.Type().String(), "*http.Response")to identify calls that return*http.Response. This matches any call whose return type's string representation contains*http.Response, including functions that return function types with*http.Responseas a parameter (e.g.func(*http.Response) error).This causes false positives with libraries like
carlmjohnson/requests(ToBytesBufferreturnsfunc(*http.Response) error) andhashicorp/go-retryablehttp(CheckRetryisfunc(context.Context, *http.Response, error) (bool, error)).Solution
Replace
strings.Containswithtypes.Identicalto compare the return type precisely:*http.Response*types.Tuple): check each elementThis also makes the
ResponseControllerexclusion hack unnecessary, astypes.Identicalnaturally skips it.If there was an intentional reason for using string-based matching, my apologies — I may have missed the context.
Test
Added
testdata/src/a/function_type.goto verify that calls returning function types containing*http.Responseas a parameter are not flagged.