Skip to content

Commit 9356f33

Browse files
committed
merge FuncData into Optional
1 parent db1510d commit 9356f33

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

checker/checker.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,18 @@ func (v *Checker) ident(node ast.Node, name string, strict, builtins bool) Natur
264264
if builtins {
265265
if fn, ok := v.config.Functions[name]; ok {
266266
nt := v.config.NtCache.FromType(fn.Type())
267-
if nt.FuncData == nil {
268-
nt.FuncData = new(FuncData)
267+
if nt.Optional == nil {
268+
nt.Optional = new(Optional)
269269
}
270-
nt.FuncData.Func = fn
270+
nt.Optional.Func = fn
271271
return nt
272272
}
273273
if fn, ok := v.config.Builtins[name]; ok {
274274
nt := v.config.NtCache.FromType(fn.Type())
275-
if nt.FuncData == nil {
276-
nt.FuncData = new(FuncData)
275+
if nt.Optional == nil {
276+
nt.Optional = new(Optional)
277277
}
278-
nt.FuncData.Func = fn
278+
nt.Optional.Func = fn
279279
return nt
280280
}
281281
}
@@ -644,8 +644,8 @@ func (v *Checker) callNode(node *ast.CallNode) Nature {
644644
return Nature{}
645645
}
646646

647-
if nt.FuncData != nil && nt.FuncData.Func != nil {
648-
return v.checkFunction(nt.FuncData.Func, node, node.Arguments)
647+
if nt.Optional != nil && nt.Optional.Func != nil {
648+
return v.checkFunction(nt.Optional.Func, node, node.Arguments)
649649
}
650650

651651
fnName := "function"

checker/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func MethodIndex(c *Cache, env Nature, node ast.Node) (bool, int, string) {
3232
switch n := node.(type) {
3333
case *ast.IdentifierNode:
3434
if env.Kind == reflect.Struct {
35-
if m, ok := env.Get(c, n.Value); ok && m.FuncData != nil {
35+
if m, ok := env.Get(c, n.Value); ok && m.Optional != nil {
3636
return m.Method, m.MethodIndex, n.Value
3737
}
3838
}

checker/nature/nature.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type Nature struct {
3838
Kind reflect.Kind // Kind of the value.
3939

4040
*Optional
41-
*FuncData
4241

4342
// Ref is a reference used for multiple, disjoint purposes. When the Nature
4443
// is for a:
@@ -61,16 +60,13 @@ type Optional struct {
6160
Fields map[string]Nature // Fields of map type.
6261
DefaultMapValue *Nature // Default value of map type.
6362

64-
pkgPathSet bool
65-
}
66-
67-
type FuncData struct {
68-
Func *builtin.Function // Used to pass function type from callee to CallNode.
69-
MethodIndex int // Index of method in type.
70-
63+
// callable-only data
64+
Func *builtin.Function // Used to pass function type from callee to CallNode.
65+
MethodIndex int // Index of method in type.
7166
inElem, outZero *Nature
7267
numIn, numOut int
7368

69+
pkgPathSet bool
7470
isVariadic bool
7571
isVariadicSet bool
7672
numInSet bool
@@ -104,15 +100,15 @@ func (c *Cache) FromType(t reflect.Type) Nature {
104100
if t == nil {
105101
return Nature{}
106102
}
107-
var fd *FuncData
103+
var opt *Optional
108104
k := t.Kind()
109105
switch k {
110106
case reflect.Struct:
111107
return c.getStruct(t)
112108
case reflect.Func:
113-
fd = new(FuncData)
109+
opt = new(Optional)
114110
}
115-
return Nature{Type: t, Kind: k, FuncData: fd}
111+
return Nature{Type: t, Kind: k, Optional: opt}
116112
}
117113

118114
func (c *Cache) getStruct(t reflect.Type) Nature {
@@ -134,6 +130,9 @@ func (c *Cache) getStruct(t reflect.Type) Nature {
134130
},
135131
},
136132
}
133+
if c != nil {
134+
c.structs[t] = nt
135+
}
137136
return nt
138137
}
139138

@@ -416,7 +415,7 @@ func (n *Nature) All(c *Cache) map[string]Nature {
416415
method := n.Type.Method(i)
417416
nt := c.FromType(method.Type)
418417
if nt.Optional == nil {
419-
nt.FuncData = new(FuncData)
418+
nt.Optional = new(Optional)
420419
}
421420
nt.Method = true
422421
nt.MethodIndex = method.Index

0 commit comments

Comments
 (0)