Skip to content

Commit a248a6c

Browse files
committed
Fix NPE
1 parent 75210e7 commit a248a6c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

parser_types.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func (r *parser) evalType(info *infoFile, expr ast.Expr) (ret Type) {
3838
return r.evalType(info, t.Type)
3939
case *ast.CompositeLit:
4040
typ := r.evalType(info, t.Type)
41+
if typ == nil {
42+
return nil
43+
}
44+
4145
if typ.Kind() != Struct {
4246
return typ
4347
}
@@ -55,7 +59,16 @@ func (r *parser) evalType(info *infoFile, expr ast.Expr) (ret Type) {
5559
name := t.Sel.Name
5660
return newSelector(s, name)
5761
case *ast.IndexExpr:
58-
return r.evalType(info, t.X).Elem()
62+
typ := r.evalType(info, t.X)
63+
if typ == nil {
64+
return nil
65+
}
66+
67+
switch typ.Kind() {
68+
case Array, Chan, Map, Ptr, Slice:
69+
return typ.Elem()
70+
}
71+
return nil
5972
case *ast.SliceExpr:
6073
return r.evalType(info, t.X)
6174
case *ast.TypeAssertExpr:
@@ -80,6 +93,9 @@ func (r *parser) evalType(info *infoFile, expr ast.Expr) (ret Type) {
8093
}
8194

8295
b := r.evalType(info, t.Fun)
96+
if b == nil {
97+
return nil
98+
}
8399
for b.Kind() == Declaration {
84100
b = b.Declaration()
85101
}

testdata/value/b.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ var (
2323
// Name:"MyPrintf"
2424
// To:"Declaration" String:"fmt.Printf"
2525
// To:"Declaration,Declaration" Kind:"Func" String:"func(format, a...) (n, err)"
26-
// To:"Declaration,Declaration,In:1,Declaration" String:"[]interface{}"
2726
MyPrintf = fmt.Printf
2827

2928
// Name:"ts" Value:""

0 commit comments

Comments
 (0)