cl: fix null pointer in processing debug location

This commit is contained in:
Li Jie
2025-01-19 19:02:31 +08:00
parent 491a23b21e
commit 164c3e0e7b

View File

@@ -318,7 +318,9 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
func (p *context) getFuncBodyPos(f *ssa.Function) token.Position { func (p *context) getFuncBodyPos(f *ssa.Function) token.Position {
if f.Object() != nil { if f.Object() != nil {
return p.goProg.Fset.Position(f.Object().(*types.Func).Scope().Pos()) if fn, ok := f.Object().(*types.Func); ok && fn.Scope() != nil {
return p.goProg.Fset.Position(fn.Scope().Pos())
}
} }
return p.goProg.Fset.Position(f.Pos()) return p.goProg.Fset.Position(f.Pos())
} }
@@ -760,6 +762,9 @@ func (p *context) getDebugLocScope(v *ssa.Function, pos token.Pos) *types.Scope
return nil return nil
} }
funcScope := v.Object().(*types.Func).Scope() funcScope := v.Object().(*types.Func).Scope()
if funcScope == nil {
return nil
}
return funcScope.Innermost(pos) return funcScope.Innermost(pos)
} }