Skip to content

Commit e2e7ec9

Browse files
authored
Merge pull request #16 from BlackVectorOps/fix/safe-type-assertion-topology-4482181730806486940
Refactor: Use safe type assertion helper for closures in topology analysis
2 parents 8c90626 + 1bd373a commit e2e7ec9

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

pkg/analysis/topology/topology.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,8 @@ func extractCallSignature(call *ssa.Call) string {
298298
case *ssa.Builtin:
299299
return fmt.Sprintf("builtin:%s", v.Name())
300300
case *ssa.MakeClosure:
301-
// FIX: Use Safe Type Assertion to avoid panic
302-
if fn, ok := v.Fn.(*ssa.Function); ok && fn != nil {
303-
return fmt.Sprintf("closure:%s", fn.Signature.String())
301+
if sig := extractClosureSignature(v); sig != "" {
302+
return sig
304303
}
305304
}
306305

@@ -326,9 +325,8 @@ func extractGoSignature(g *ssa.Go) string {
326325
case *ssa.Function:
327326
return extractFunctionSig(v)
328327
case *ssa.MakeClosure:
329-
// FIX: Use Safe Type Assertion
330-
if fn, ok := v.Fn.(*ssa.Function); ok && fn != nil {
331-
return fmt.Sprintf("closure:%s", fn.Signature.String())
328+
if sig := extractClosureSignature(v); sig != "" {
329+
return sig
332330
}
333331
}
334332
// Fallback for dynamic function pointers
@@ -349,9 +347,8 @@ func extractDeferSignature(d *ssa.Defer) string {
349347
case *ssa.Function:
350348
return extractFunctionSig(v)
351349
case *ssa.MakeClosure:
352-
// FIX: Use Safe Type Assertion
353-
if fn, ok := v.Fn.(*ssa.Function); ok && fn != nil {
354-
return fmt.Sprintf("closure:%s", fn.Signature.String())
350+
if sig := extractClosureSignature(v); sig != "" {
351+
return sig
355352
}
356353
}
357354
if d.Call.Value != nil {
@@ -360,6 +357,13 @@ func extractDeferSignature(d *ssa.Defer) string {
360357
return "unknown"
361358
}
362359

360+
func extractClosureSignature(v *ssa.MakeClosure) string {
361+
if fn, ok := v.Fn.(*ssa.Function); ok && fn != nil {
362+
return fmt.Sprintf("closure:%s", fn.Signature.String())
363+
}
364+
return ""
365+
}
366+
363367
func extractFunctionSig(fn *ssa.Function) string {
364368
// Fix: Detect anonymous/nested functions to provide stable signatures.
365369
// This handles optimizations where simple closures become plain Functions.

0 commit comments

Comments
 (0)