Repository navigation
feat(golang): Implement calls, closures, and control flow statements (PR-06 complete) - #525
Merged
Merged
Conversation
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #525 +/- ##
==========================================
- Coverage 83.02% 82.82% -0.20%
==========================================
Files 127 130 +3
Lines 14836 15193 +357
==========================================
+ Hits 12317 12583 +266
- Misses 2061 2139 +78
- Partials 458 471 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
shivasurya
added a commit
that referenced
this pull request
Feb 14, 2026
Implements closure and concurrency statement parsing as the second part of PR-06 breakdown:
**New Files:**
- graph/golang/closures.go (93 lines)
- ClosureInfo struct with Params, ReturnType, LineNumber, StartByte, EndByte
- ParseFuncLiteral: handles func literals with params/returns
- ParseDeferStatement: extracts call from defer statement
- ParseGoStatement: extracts call from go statement
- graph/golang/closures_test.go (259 lines)
- 5 test cases for ParseFuncLiteral (simple, no params, multi params, multi returns, IIFE)
- 3 test cases for ParseDeferStatement (method, function, with args)
- 3 test cases for ParseGoStatement (function, method, closure)
- Nil/error handling tests
**Modified Files:**
- parser_golang.go (added lines 227-394)
- anonCounters map for tracking anonymous function names per parent
- generateAnonName: generates $anon_N names scoped to parent context
- parseGoFuncLiteral: creates func_literal nodes, returns node as currentContext
- parseGoDeferStatement: creates defer_call nodes with edge to parent
- parseGoGoStatement: creates go_call nodes with edge to parent
- parser.go
- Filled func_literal stub (returns currentContext for body traversal)
- Filled defer_statement stub
- Filled go_statement stub
- helpers.go
- Fixed ExtractParameters to initialize with empty slices (not nil)
**Verification:**
- go build ./... passes
- go vet ./... passes
- go test ./graph/golang/... passes with 94.6% coverage
- go test ./graph/... passes (no regressions)
**Test Examples:**
- func(x int) int { return x + 1 } → Type: "func_literal", Name: "$anon_1", Params: ["x"], ReturnType: "int"
- defer f.Close() → Type: "defer_call", Name: "Close", Interface: ["f"]
- go handler(conn) → Type: "go_call", Name: "handler", Arguments: ["conn"]
**Design Decisions:**
1. Anonymous naming: $anon_N scoped to parent function using anonCounters map
2. func_literal returns node: Becomes currentContext for closure body traversal
3. defer/go create edges: Uses graph.AddEdge(currentContext, node) pattern
4. Empty slices: ExtractParameters now initializes with []string{} for consistency
Stacked on: PR-06a (#525)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
shivasurya
added a commit
that referenced
this pull request
Feb 14, 2026
Implements control flow statement parsing as the final part of PR-06 breakdown:
**New Files:**
- graph/golang/statements.go (177 lines)
- ReturnInfo struct with Values, LineNumber, StartByte, EndByte
- ParseReturnStatement: handles single/multiple return values
- ForInfo struct with IsRange, Condition, Init, Update, Left, Right fields
- ParseForStatement: handles C-style, range, while-style, and infinite loops
- IfInfo struct with Condition, LineNumber, StartByte, EndByte
- ParseIfStatement: extracts if statement condition
- graph/golang/statements_test.go (306 lines)
- 5 test cases for ParseReturnStatement (single, multiple, expression, no values, function call)
- 5 test cases for ParseForStatement (C-style, range with index/value, range with blank, infinite, while-style)
- 4 test cases for ParseIfStatement (simple, complex condition, function call, with assignment)
- Nil/error handling tests
**Modified Files:**
- parser_golang.go (added lines 417-556)
- parseGoReturnStatement: creates ReturnStmt model nodes with model.ReturnStmt
- parseGoForStatement: creates ForStmt model nodes with model.ForStmt
- parseGoIfStatement: creates IfStmt model nodes with model.IfStmt
- joinStrings: helper to join string slices with commas
- Uses GenerateSha256 for statement IDs (NOT GenerateMethodID)
- Does NOT create edges for statement nodes (Python pattern)
- parser.go
- Added Go handler to return_statement case (line 30-32)
- Added Go handler to for_statement case (line 66-68)
- Added Go handler to if_statement case (line 59-61)
- Lint fixes (comment periods added to all files, switch statement refactor)
**Verification:**
- go build ./... passes
- go vet ./... passes
- go test ./graph/golang/... passes with 94.6% coverage
- go test ./graph/... passes (no regressions)
- golangci-lint run passes (fixed comment periods, switch statement)
**Test Examples:**
- return 42 → Type: "ReturnStmt", Values: ["42"]
- return 0, nil → Type: "ReturnStmt", Values: ["0", "nil"]
- for i := 0; i < 10; i++ {} → Type: "ForStmt", IsRange: false, Condition: "i < 10"
- for _, v := range items {} → Type: "ForStmt", IsRange: true, Left: "_, v", Right: "items"
- if err != nil { } → Type: "IfStmt", Condition: "err != nil"
**Design Decisions:**
1. Statement IDs: Uses GenerateSha256 following Python pattern (NOT GenerateMethodID)
2. No edge creation: Statement nodes don't create edges (Python pattern)
3. model objects: Creates minimal model.ReturnStmt, model.ForStmt, model.IfStmt wrappers
4. While-style loops: Stores condition in Init field for consistency
5. Switch statement: Refactored if-else chain for better performance
Stacked on: PR-06a (#525), PR-06b
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
shivasurya
force-pushed
the
shiva/golang-pr06-calls-closures
branch
from
February 14, 2026 21:43
bc3041f to
fb3a103
Compare
This was referenced Feb 15, 2026
Owner
Author
This was referenced Feb 15, 2026
Owner
Author
Merge activity
|
shivasurya
changed the base branch from
shiva/golang-pr05-variables
to
graphite-base/525
February 15, 2026 04:07
Implements call expression parsing as the first part of PR-06 breakdown:
**New Files:**
- graph/golang/calls.go (111 lines)
- CallInfo struct with FunctionName, ObjectName, Arguments, IsSelector
- ParseCallExpression: handles simple calls, method calls, package calls
- ParseSelectorExpression: extracts object and field from selector
- extractArguments: helper for extracting argument list
- graph/golang/calls_test.go (185 lines)
- 6 test cases for ParseCallExpression (simple, method, package, no args, chained, complex args)
- 3 test cases for ParseSelectorExpression
- Nil/error handling tests
**Modified Files:**
- parser_golang.go
- parseGoCallExpression dispatcher creates call/method_expression nodes
- CRITICAL: Uses graph.AddEdge(currentContext, callNode) for parent-child linking
- Stores ObjectName in Interface field for method calls
- parser.go
- Filled call_expression stub with parseGoCallExpression call
**Verification:**
- go build ./... passes
- go vet ./... passes
- go test ./graph/golang/... passes with 94.0% coverage
- go test ./graph/... passes (no regressions)
- ParseCallExpression: 76.2% (func_literal case deferred to PR-06b)
**Test Examples:**
- fmt.Println("hello") → Type: "method_expression", Name: "Println", Interface: ["fmt"]
- foo(x, y) → Type: "call", Name: "foo", Arguments: ["x", "y"]
- obj.Method(a) → Type: "method_expression", Name: "Method", Interface: ["obj"]
Stacked on: shiva/golang-pr05-variables
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implements closure and concurrency statement parsing as the second part of PR-06 breakdown:
**New Files:**
- graph/golang/closures.go (93 lines)
- ClosureInfo struct with Params, ReturnType, LineNumber, StartByte, EndByte
- ParseFuncLiteral: handles func literals with params/returns
- ParseDeferStatement: extracts call from defer statement
- ParseGoStatement: extracts call from go statement
- graph/golang/closures_test.go (259 lines)
- 5 test cases for ParseFuncLiteral (simple, no params, multi params, multi returns, IIFE)
- 3 test cases for ParseDeferStatement (method, function, with args)
- 3 test cases for ParseGoStatement (function, method, closure)
- Nil/error handling tests
**Modified Files:**
- parser_golang.go (added lines 227-394)
- anonCounters map for tracking anonymous function names per parent
- generateAnonName: generates $anon_N names scoped to parent context
- parseGoFuncLiteral: creates func_literal nodes, returns node as currentContext
- parseGoDeferStatement: creates defer_call nodes with edge to parent
- parseGoGoStatement: creates go_call nodes with edge to parent
- parser.go
- Filled func_literal stub (returns currentContext for body traversal)
- Filled defer_statement stub
- Filled go_statement stub
- helpers.go
- Fixed ExtractParameters to initialize with empty slices (not nil)
**Verification:**
- go build ./... passes
- go vet ./... passes
- go test ./graph/golang/... passes with 94.6% coverage
- go test ./graph/... passes (no regressions)
**Test Examples:**
- func(x int) int { return x + 1 } → Type: "func_literal", Name: "$anon_1", Params: ["x"], ReturnType: "int"
- defer f.Close() → Type: "defer_call", Name: "Close", Interface: ["f"]
- go handler(conn) → Type: "go_call", Name: "handler", Arguments: ["conn"]
**Design Decisions:**
1. Anonymous naming: $anon_N scoped to parent function using anonCounters map
2. func_literal returns node: Becomes currentContext for closure body traversal
3. defer/go create edges: Uses graph.AddEdge(currentContext, node) pattern
4. Empty slices: ExtractParameters now initializes with []string{} for consistency
Stacked on: PR-06a (#525)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implements control flow statement parsing as the final part of PR-06 breakdown:
**New Files:**
- graph/golang/statements.go (177 lines)
- ReturnInfo struct with Values, LineNumber, StartByte, EndByte
- ParseReturnStatement: handles single/multiple return values
- ForInfo struct with IsRange, Condition, Init, Update, Left, Right fields
- ParseForStatement: handles C-style, range, while-style, and infinite loops
- IfInfo struct with Condition, LineNumber, StartByte, EndByte
- ParseIfStatement: extracts if statement condition
- graph/golang/statements_test.go (306 lines)
- 5 test cases for ParseReturnStatement (single, multiple, expression, no values, function call)
- 5 test cases for ParseForStatement (C-style, range with index/value, range with blank, infinite, while-style)
- 4 test cases for ParseIfStatement (simple, complex condition, function call, with assignment)
- Nil/error handling tests
**Modified Files:**
- parser_golang.go (added lines 417-556)
- parseGoReturnStatement: creates ReturnStmt model nodes with model.ReturnStmt
- parseGoForStatement: creates ForStmt model nodes with model.ForStmt
- parseGoIfStatement: creates IfStmt model nodes with model.IfStmt
- joinStrings: helper to join string slices with commas
- Uses GenerateSha256 for statement IDs (NOT GenerateMethodID)
- Does NOT create edges for statement nodes (Python pattern)
- parser.go
- Added Go handler to return_statement case (line 30-32)
- Added Go handler to for_statement case (line 66-68)
- Added Go handler to if_statement case (line 59-61)
- Lint fixes (comment periods added to all files, switch statement refactor)
**Verification:**
- go build ./... passes
- go vet ./... passes
- go test ./graph/golang/... passes with 94.6% coverage
- go test ./graph/... passes (no regressions)
- golangci-lint run passes (fixed comment periods, switch statement)
**Test Examples:**
- return 42 → Type: "ReturnStmt", Values: ["42"]
- return 0, nil → Type: "ReturnStmt", Values: ["0", "nil"]
- for i := 0; i < 10; i++ {} → Type: "ForStmt", IsRange: false, Condition: "i < 10"
- for _, v := range items {} → Type: "ForStmt", IsRange: true, Left: "_, v", Right: "items"
- if err != nil { } → Type: "IfStmt", Condition: "err != nil"
**Design Decisions:**
1. Statement IDs: Uses GenerateSha256 following Python pattern (NOT GenerateMethodID)
2. No edge creation: Statement nodes don't create edges (Python pattern)
3. model objects: Creates minimal model.ReturnStmt, model.ForStmt, model.IfStmt wrappers
4. While-style loops: Stores condition in Init field for consistency
5. Switch statement: Refactored if-else chain for better performance
Stacked on: PR-06a (#525), PR-06b
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove unnecessary uint32() conversions in calls.go, closures.go, statements.go (StartPoint().Row already returns uint32) - Preallocate vars slice with capacity in variables.go for better performance - Fixes all remaining golangci-lint issues (unconvert, prealloc) Verification: - golangci-lint run passes (0 issues) - go test ./graph/golang/... passes
shivasurya
force-pushed
the
shiva/golang-pr06-calls-closures
branch
from
February 15, 2026 04:09
fb3a103 to
88ad1e7
Compare
Code Pathfinder Security ScanNo security issues detected.
Powered by Code Pathfinder |
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.




Summary
Complete implementation of PR-06 (Calls, Closures & Statements), broken down into three focused sub-PRs for easier review. Implements call expressions, function literals, defer/go statements, and control flow statements (return, for, if).
Changes
PR-06a: Call Expressions (#cf466cd)
New Files:
graph/golang/calls.go(111 lines)CallInfostruct: FunctionName, ObjectName, Arguments, IsSelectorParseCallExpression: Handles simple calls, method calls, package callsParseSelectorExpression: Extracts object and field from selector_expressionextractArguments: Helper to extract arguments from argument_listgraph/golang/calls_test.go(185 lines)Modified Files:
parser_golang.goparseGoCallExpressiondispatcher (lines 227-274)graph.AddEdge(currentContext, callNode)for parent-child linkingparser.goPR-06b: Closures, Defer & Go Statements (#3d1b667)
New Files:
graph/golang/closures.go(93 lines)ClosureInfostruct: Params, ReturnType, LineNumber, StartByte, EndByteParseFuncLiteral: Handles func literals with params/returnsParseDeferStatement: Extracts call from defer statementParseGoStatement: Extracts call from go statementgraph/golang/closures_test.go(259 lines)Modified Files:
parser_golang.go(added lines 277-394)anonCountersmap for tracking anonymous function names per parentgenerateAnonName: Generates $anon_N names scoped to parent contextparseGoFuncLiteral: Creates func_literal nodes, returns node as currentContextparseGoDeferStatement: Creates defer_call nodes with edge to parentparseGoGoStatement: Creates go_call nodes with edge to parenthelpers.goparser.goPR-06c: Control Flow Statements (#2067448)
New Files:
graph/golang/statements.go(177 lines)ReturnInfostruct: Values, LineNumber, StartByte, EndByteParseReturnStatement: Handles single/multiple return valuesForInfostruct: IsRange, Condition, Init, Update, Left, RightParseForStatement: Handles C-style, range, while-style, infinite loopsIfInfostruct: Condition, LineNumber, StartByte, EndByteParseIfStatement: Extracts if statement conditiongraph/golang/statements_test.go(306 lines)Modified Files:
parser_golang.go(added lines 417-556)parseGoReturnStatement: Creates ReturnStmt model nodesparseGoForStatement: Creates ForStmt model nodesparseGoIfStatement: Creates IfStmt model nodesjoinStrings: Helper to join string slices with commasparser.goLint fixes: Added comment periods, refactored to switch statement
Test Results
Coverage Details
Examples
PR-06a: Call Expressions
fmt.Println("hello")foo(x, y)obj.Method(a, b)bar()PR-06b: Closures, Defer & Go
func(x int) int { return x + 1 }defer f.Close()go handler(conn)PR-06c: Control Flow Statements
return 42return 0, nilfor i := 0; i < 10; i++ {}for _, v := range items {}if err != nil {}Design Decisions
PR-06a: Call Expressions
graph.AddEdge(currentContext, callNode)for parent-child linking (CRITICAL for call graph construction in PR-08)arguments := []string{}for consistencyPR-06b: Closures
PR-06c: Statements
Stack
Verification Against PR-06 Doc
PR-06a
✅ CallInfo struct matches spec
✅ ParseCallExpression handles simple/method/package calls
✅ ParseSelectorExpression extracts object and field
✅ graph.AddEdge creates parent-child relationship
✅ Tests cover all call types from doc examples
PR-06b
✅ ClosureInfo struct matches spec
✅ ParseFuncLiteral handles params and return types
✅ ParseDeferStatement/ParseGoStatement extract calls
✅ Anonymous function naming: $anon_N scoped to parent
✅ func_literal returns node for currentContext
✅ defer/go create edges with graph.AddEdge
PR-06c
✅ ReturnInfo/ForInfo/IfInfo structs match spec
✅ ParseReturnStatement handles single/multiple values
✅ ParseForStatement handles C-style, range, while-style, infinite loops
✅ ParseIfStatement extracts condition
✅ Statement nodes use GenerateSha256 (not GenerateMethodID)
✅ Statement nodes don't create edges
🤖 Generated with Claude Code