Skip to content

feat(go): eager scope creation + parameter-aware RHS inference#642

Open
shivasurya wants to merge 2 commits intoshiva/pr-01-golang-thirdpartyfrom
shiva/pr-02-golang-thirdparty
Open

feat(go): eager scope creation + parameter-aware RHS inference#642
shivasurya wants to merge 2 commits intoshiva/pr-01-golang-thirdpartyfrom
shiva/pr-02-golang-thirdparty

Conversation

@shivasurya
Copy link
Copy Markdown
Owner

Summary

  • Fix B.1 (eager scope creation): indexGoFunctions now accepts a GoTypeInferenceEngine and eagerly creates an empty GoFunctionScope for every indexed Go function during Pass 1. Eliminates [debug-1b] no scope for log messages for functions where all Pass 2b variable inferences fail.
  • Fix B.2 (param-aware RHS inference): New inferTypeFromParamMethodCall helper resolves method return types when the receiver matches a function parameter (e.g. r.FormValue("id")builtin.string via net/http.Request). Threads callGraph through ExtractGoVariableAssignments and its 5-function call chain.
  • Duplicates splitGoTypeFQN / resolveGoTypeFQN in the extraction package to avoid an import cycle with builder.

Test plan

  • TestIndexGoFunctions_EagerScopeCreation — scope exists for every indexed function
  • TestIndexGoFunctions_EagerScope_NilTypeEngine — no panic with nil engine
  • TestIndexGoFunctions_EagerScope_NotOverwritten — pre-existing Pass 2b bindings preserved
  • TestParamAwareRHSInference_StdlibParamr.FormValue("id")builtin.string via StdlibLoader
  • TestParamAwareRHSInference_ThirdPartyParamc.Query("search")builtin.string via ThirdPartyLoader
  • TestParamAwareRHSInference_NilCallGraph — graceful no-op with nil callGraph
  • TestParamAwareRHSInference_UnknownParam — no binding for non-parameter receiver
  • Full suite: go test ./... — 29/29 packages pass
  • Lint: golangci-lint run — 0 issues

🤖 Generated with Claude Code

Fix B.1: indexGoFunctions now accepts a GoTypeInferenceEngine and creates
an empty GoFunctionScope for every indexed Go function during Pass 1.
This ensures Pattern 1b Source 2 always finds a scope even when all
variable inferences in Pass 2b fail (e.g., functions with only
parameter-based method calls).

Fix B.2: inferTypeFromRHS gains a parameter-aware fallback via the new
inferTypeFromParamMethodCall helper. When obj.Method() is encountered
and obj matches a function parameter, the method's return type is
resolved through StdlibLoader → ThirdPartyLoader (Check 2/2.5 order).
Thread callGraph through ExtractGoVariableAssignments and the 5
functions in its call chain to enable the param lookup.

Duplicates splitGoTypeFQN / resolveGoTypeFQN in the extraction package
to avoid an import cycle between extraction and builder.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code labels Apr 5, 2026
@shivasurya shivasurya self-assigned this Apr 5, 2026
@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code labels Apr 5, 2026
@safedep
Copy link
Copy Markdown

safedep bot commented Apr 5, 2026

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

View complete scan results →

This report is generated by SafeDep Github App

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

Code Pathfinder Security Scan

Pass Critical High Medium Low Info

No security issues detected.

Metric Value
Files Scanned 7
Rules 205

Powered by Code Pathfinder

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 90.24390% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.22%. Comparing base (994c4bd) to head (3b011a2).

Files with missing lines Patch % Lines
...-engine/graph/callgraph/extraction/go_variables.go 89.61% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##           shiva/pr-01-golang-thirdparty     #642   +/-   ##
==============================================================
  Coverage                          84.21%   84.22%           
==============================================================
  Files                                162      162           
  Lines                              23256    23327   +71     
==============================================================
+ Hits                               19586    19648   +62     
- Misses                              2936     2940    +4     
- Partials                             734      739    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add targeted tests for uncovered branches in inferTypeFromParamMethodCall:
- Package alias receiver (already handled by inferTypeFromFunctionCall)
- Method not found in type's method set
- Error-only return values (no usable non-error type)
- Unqualified parameter type (no dot → extractionSplitGoTypeFQN returns false)

Coverage for inferTypeFromParamMethodCall: 83.3% → 90.5%.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant