Skip to content

Fix false positive in getReqCall: use types.Identical instead of string matching#79

Open
soh335 wants to merge 1 commit intotimakin:masterfrom
soh335:fix-issue-71
Open

Fix false positive in getReqCall: use types.Identical instead of string matching#79
soh335 wants to merge 1 commit intotimakin:masterfrom
soh335:fix-issue-71

Conversation

@soh335
Copy link
Copy Markdown

@soh335 soh335 commented Mar 11, 2026

Closes #71

Problem

getReqCall currently uses strings.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.Response as a parameter (e.g. func(*http.Response) error).

This causes false positives with libraries like carlmjohnson/requests (ToBytesBuffer returns func(*http.Response) error) and hashicorp/go-retryablehttp (CheckRetry is func(context.Context, *http.Response, error) (bool, error)).

Solution

Replace strings.Contains with types.Identical to compare the return type precisely:

  • Single return value: check if it is exactly *http.Response
  • Multiple return values (*types.Tuple): check each element

This also makes the ResponseController exclusion hack unnecessary, as types.Identical naturally 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.go to verify that calls returning function types containing *http.Response as a parameter are not flagged.

…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>
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.

False positive with carlmjohnson/requests package

1 participant