Skip to content

Commit 07dcc3d

Browse files
committed
Allow undefined function with AllowUndefinedVariables option is on
1 parent 5cb0507 commit 07dcc3d

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

checker/checker.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func Check(tree *parser.Tree, config *conf.Config) (t reflect.Type, err error) {
2828
v.types = config.Types
2929
v.operators = config.Operators
3030
v.expect = config.Expect
31-
v.undefVars = config.AllowUndefinedVariables
32-
v.undefVarsType = config.UndefinedVariableType
31+
v.strict = !config.AllowUndefinedVariables
32+
v.defaultType = config.UndefinedVariableType
3333
}
3434

3535
t = v.visit(tree.Node)
@@ -53,12 +53,12 @@ okay:
5353
}
5454

5555
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
6262
}
6363

6464
func (v *visitor) visit(node ast.Node) reflect.Type {
@@ -131,9 +131,9 @@ func (v *visitor) IdentifierNode(node *ast.IdentifierNode) reflect.Type {
131131
if t, ok := v.types[node.Value]; ok {
132132
return t.Type
133133
}
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
137137
}
138138
return interfaceType
139139
}
@@ -345,6 +345,12 @@ func (v *visitor) FunctionNode(node *ast.FunctionNode) reflect.Type {
345345
return v.checkFunc(fn, f.Method, node, node.Name, node.Arguments)
346346
}
347347
}
348+
if !v.strict {
349+
if v.defaultType != nil {
350+
return v.defaultType
351+
}
352+
return interfaceType
353+
}
348354
panic(v.error(node, "unknown func %v", node.Name))
349355
}
350356

0 commit comments

Comments
 (0)