@@ -62,27 +62,40 @@ FindCall:
62
62
return nil , 0 , fmt .Errorf ("cannot find an enclosing function" )
63
63
}
64
64
65
- qf := Qualifier (pgf .File , pkg .GetTypes (), pkg .GetTypesInfo ())
65
+ info := pkg .GetTypesInfo ()
66
+
67
+ // Get the type information for the function being called.
68
+ var sig * types.Signature
69
+ if tv , ok := info .Types [callExpr .Fun ]; ! ok {
70
+ return nil , 0 , fmt .Errorf ("cannot get type for Fun %[1]T (%[1]v)" , callExpr .Fun )
71
+ } else if tv .IsType () {
72
+ return nil , 0 , fmt .Errorf ("this is a conversion to %s, not a call" , tv .Type )
73
+ } else if sig , ok = tv .Type .Underlying ().(* types.Signature ); ! ok {
74
+ return nil , 0 , fmt .Errorf ("cannot find signature for Fun %[1]T (%[1]v)" , callExpr .Fun )
75
+ }
76
+ // Inv: sig != nil
77
+
78
+ qf := Qualifier (pgf .File , pkg .GetTypes (), info )
66
79
67
80
// Get the object representing the function, if available.
68
81
// There is no object in certain cases such as calling a function returned by
69
82
// a function (e.g. "foo()()").
70
83
var obj types.Object
71
84
switch t := callExpr .Fun .(type ) {
72
85
case * ast.Ident :
73
- obj = pkg . GetTypesInfo () .ObjectOf (t )
86
+ obj = info .ObjectOf (t )
74
87
case * ast.SelectorExpr :
75
- obj = pkg . GetTypesInfo () .ObjectOf (t .Sel )
88
+ obj = info .ObjectOf (t .Sel )
76
89
}
77
90
78
- // Built -in?
91
+ // Call to built -in?
79
92
if obj != nil && ! obj .Pos ().IsValid () {
80
- // built-in function?
93
+ // function?
81
94
if obj , ok := obj .(* types.Builtin ); ok {
82
95
return builtinSignature (ctx , snapshot , callExpr , obj .Name (), pos )
83
96
}
84
97
85
- // error.Error?
98
+ // method (only error.Error) ?
86
99
if fn , ok := obj .(* types.Func ); ok && fn .Name () == "Error" {
87
100
return & protocol.SignatureInformation {
88
101
Label : "Error()" ,
@@ -93,17 +106,6 @@ FindCall:
93
106
return nil , 0 , bug .Errorf ("call to unexpected built-in %v (%T)" , obj , obj )
94
107
}
95
108
96
- // Get the type information for the function being called.
97
- sigType := pkg .GetTypesInfo ().TypeOf (callExpr .Fun )
98
- if sigType == nil {
99
- return nil , 0 , fmt .Errorf ("cannot get type for Fun %[1]T (%[1]v)" , callExpr .Fun )
100
- }
101
-
102
- sig , _ := sigType .Underlying ().(* types.Signature )
103
- if sig == nil {
104
- return nil , 0 , fmt .Errorf ("cannot find signature for Fun %[1]T (%[1]v)" , callExpr .Fun )
105
- }
106
-
107
109
activeParam := activeParameter (callExpr , sig .Params ().Len (), sig .Variadic (), pos )
108
110
109
111
var (
0 commit comments