Skip to content

feat(go): Resolve stdlib return types in variable extraction (PR-07)#554

Merged
shivasurya merged 1 commit intomainfrom
shiva/go-stdlib-support-pr07
Feb 25, 2026
Merged

feat(go): Resolve stdlib return types in variable extraction (PR-07)#554
shivasurya merged 1 commit intomainfrom
shiva/go-stdlib-support-pr07

Conversation

@shivasurya
Copy link
Owner

Summary

  • Extends Pass 2b (variable extraction) to resolve return types of Go stdlib function calls via the StdlibLoader attached to the module registry
  • Previously, variables assigned from stdlib calls (e.g., resp := http.Get(url)) remained untyped; now they receive a concrete TypeFQN (e.g., net/http.Response)
  • Adds inferTypeFromStdlibFunction helper that validates the import path is stdlib, calls StdlibLoader.GetFunction, and picks the first non-error return
  • Adds normalizeStdlibReturnType helper that converts raw JSON type strings ("*Request", "string", "io.Reader") to TypeFQNs ("net/http.Request", "builtin.string", "io.Reader")
  • Graceful degradation: when StdlibLoader is nil (network unavailable), variables remain untyped and no error is raised
  • 21 new tests in go_variables_stdlib_test.go covering both helpers (unit) and three end-to-end ExtractGoVariableAssignments scenarios

Test plan

  • go test ./graph/callgraph/extraction/... -v -run "TestNormalize|TestInferTypeFromStdlib|TestExtractGoVariables_Stdlib" — all 21 pass
  • go test ./... — all 29 packages pass
  • golangci-lint run ./graph/callgraph/extraction/... — 0 issues
  • normalizeStdlibReturnType — 100% coverage; inferTypeFromStdlibFunction — 93.3%

🤖 Generated with Claude Code

@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code labels Feb 25, 2026
@shivasurya shivasurya self-assigned this Feb 25, 2026
@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code labels Feb 25, 2026
@safedep
Copy link

safedep bot commented Feb 25, 2026

SafeDep Report Summary

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

No dependency changes detected. Nothing to scan.

This report is generated by SafeDep Github App

@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.32%. Comparing base (7a52822) to head (14ce58c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...-engine/graph/callgraph/extraction/go_variables.go 94.44% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #554      +/-   ##
==========================================
+ Coverage   83.25%   83.32%   +0.06%     
==========================================
  Files         143      143              
  Lines       17710    17746      +36     
==========================================
+ Hits        14744    14786      +42     
+ Misses       2426     2423       -3     
+ Partials      540      537       -3     

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

Copy link
Owner Author

shivasurya commented Feb 25, 2026

Merge activity

  • Feb 25, 3:17 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Feb 25, 3:29 AM UTC: Graphite rebased this pull request as part of a merge.
  • Feb 25, 3:30 AM UTC: @shivasurya merged this pull request with Graphite.

@shivasurya shivasurya changed the base branch from shiva/go-stdlib-support-pr06 to graphite-base/554 February 25, 2026 03:26
@shivasurya shivasurya changed the base branch from graphite-base/554 to main February 25, 2026 03:27
…R-25)

Extends the Go variable extraction pass (Pass 2b) to resolve return types
of stdlib function calls using the StdlibLoader attached to the module
registry.

Previously, variables assigned from stdlib calls (e.g., `resp := http.Get(url)`)
remained untyped because the TypeInferenceEngine only covers project-defined
functions. Now, when the engine has no entry for a call, the extraction pass
consults the StdlibLoader as a fallback.

Changes:
- inferTypeFromFunctionCall: falls back to inferTypeFromStdlibFunction
  after a TypeInferenceEngine miss
- inferTypeFromStdlibFunction: new helper — validates the import path is
  stdlib, calls StdlibLoader.GetFunction, picks the first non-error return
- normalizeStdlibReturnType: new helper — converts raw JSON type strings
  ("*Request", "string", "io.Reader") to TypeFQNs ("net/http.Request",
  "builtin.string", "io.Reader")
- go_variables_stdlib_test.go: 21 new tests covering both helpers and
  three integration scenarios via ExtractGoVariableAssignments

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@shivasurya shivasurya force-pushed the shiva/go-stdlib-support-pr07 branch from 85b7a94 to 14ce58c Compare February 25, 2026 03:28
@github-actions
Copy link

Code Pathfinder Security Scan

Pass Critical High Medium Low Info

No security issues detected.

Metric Value
Files Scanned 2
Rules 38

Powered by Code Pathfinder

@shivasurya shivasurya merged commit 806a944 into main Feb 25, 2026
5 checks passed
@shivasurya shivasurya deleted the shiva/go-stdlib-support-pr07 branch February 25, 2026 03:30
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