Skip to content

Commit

Permalink
Allow undefined function with AllowUndefinedVariables option is on
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Feb 27, 2020
1 parent 5cb0507 commit 07dcc3d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func Check(tree *parser.Tree, config *conf.Config) (t reflect.Type, err error) {
v.types = config.Types
v.operators = config.Operators
v.expect = config.Expect
v.undefVars = config.AllowUndefinedVariables
v.undefVarsType = config.UndefinedVariableType
v.strict = !config.AllowUndefinedVariables
v.defaultType = config.UndefinedVariableType
}

t = v.visit(tree.Node)
Expand All @@ -53,12 +53,12 @@ okay:
}

type visitor struct {
types conf.TypesTable
operators conf.OperatorsTable
expect reflect.Kind
collections []reflect.Type
undefVars bool
undefVarsType reflect.Type
types conf.TypesTable
operators conf.OperatorsTable
expect reflect.Kind
collections []reflect.Type
strict bool
defaultType reflect.Type
}

func (v *visitor) visit(node ast.Node) reflect.Type {
Expand Down Expand Up @@ -131,9 +131,9 @@ func (v *visitor) IdentifierNode(node *ast.IdentifierNode) reflect.Type {
if t, ok := v.types[node.Value]; ok {
return t.Type
}
if v.undefVars {
if v.undefVarsType != nil {
return v.undefVarsType
if !v.strict {
if v.defaultType != nil {
return v.defaultType
}
return interfaceType
}
Expand Down Expand Up @@ -345,6 +345,12 @@ func (v *visitor) FunctionNode(node *ast.FunctionNode) reflect.Type {
return v.checkFunc(fn, f.Method, node, node.Name, node.Arguments)
}
}
if !v.strict {
if v.defaultType != nil {
return v.defaultType
}
return interfaceType
}
panic(v.error(node, "unknown func %v", node.Name))
}

Expand Down

0 comments on commit 07dcc3d

Please sign in to comment.