@@ -28,8 +28,8 @@ func Check(tree *parser.Tree, config *conf.Config) (t reflect.Type, err error) {
28
28
v .types = config .Types
29
29
v .operators = config .Operators
30
30
v .expect = config .Expect
31
- v .undefVars = config .AllowUndefinedVariables
32
- v .undefVarsType = config .UndefinedVariableType
31
+ v .strict = ! config .AllowUndefinedVariables
32
+ v .defaultType = config .UndefinedVariableType
33
33
}
34
34
35
35
t = v .visit (tree .Node )
@@ -53,12 +53,12 @@ okay:
53
53
}
54
54
55
55
type visitor struct {
56
- types conf.TypesTable
57
- operators conf.OperatorsTable
58
- expect reflect.Kind
59
- collections []reflect.Type
60
- undefVars bool
61
- undefVarsType reflect.Type
56
+ types conf.TypesTable
57
+ operators conf.OperatorsTable
58
+ expect reflect.Kind
59
+ collections []reflect.Type
60
+ strict bool
61
+ defaultType reflect.Type
62
62
}
63
63
64
64
func (v * visitor ) visit (node ast.Node ) reflect.Type {
@@ -131,9 +131,9 @@ func (v *visitor) IdentifierNode(node *ast.IdentifierNode) reflect.Type {
131
131
if t , ok := v .types [node .Value ]; ok {
132
132
return t .Type
133
133
}
134
- if v . undefVars {
135
- if v .undefVarsType != nil {
136
- return v .undefVarsType
134
+ if ! v . strict {
135
+ if v .defaultType != nil {
136
+ return v .defaultType
137
137
}
138
138
return interfaceType
139
139
}
@@ -345,6 +345,12 @@ func (v *visitor) FunctionNode(node *ast.FunctionNode) reflect.Type {
345
345
return v .checkFunc (fn , f .Method , node , node .Name , node .Arguments )
346
346
}
347
347
}
348
+ if ! v .strict {
349
+ if v .defaultType != nil {
350
+ return v .defaultType
351
+ }
352
+ return interfaceType
353
+ }
348
354
panic (v .error (node , "unknown func %v" , node .Name ))
349
355
}
350
356
0 commit comments