MCPcopy
hub / github.com/expr-lang/expr / check

Method check

checker/checker.go:125–158  ·  view source on GitHub ↗
(tree *parser.Tree)

Source from the content-addressed store, hash-verified

123}
124
125func (v *Checker) check(tree *parser.Tree) (reflect.Type, error) {
126 nt := v.visit(tree.Node)
127
128 // To keep compatibility with previous versions, we should return any, if nature is unknown.
129 t := nt.Type
130 if t == nil {
131 t = anyType
132 }
133
134 if v.err != nil {
135 return t, v.err.Bind(tree.Source)
136 }
137
138 if v.config.Expect != reflect.Invalid {
139 if v.config.ExpectAny {
140 if nt.IsUnknown(&v.config.NtCache) {
141 return t, nil
142 }
143 }
144
145 switch v.config.Expect {
146 case reflect.Int, reflect.Int64, reflect.Float64:
147 if !nt.IsNumber() {
148 return nil, fmt.Errorf("expected %v, but got %s", v.config.Expect, nt.String())
149 }
150 default:
151 if nt.Kind != v.config.Expect {
152 return nil, fmt.Errorf("expected %v, but got %s", v.config.Expect, nt.String())
153 }
154 }
155 }
156
157 return t, nil
158}
159
160func (v *Checker) reset(config *conf.Config) {
161 if v.needsReset {

Callers 1

CheckMethod · 0.95

Implementers 3

Configconf/config.go
Checkerchecker/checker.go
OperatorOverloadingpatcher/operator_override.go

Calls 6

visitMethod · 0.95
BindMethod · 0.80
IsUnknownMethod · 0.80
IsNumberMethod · 0.80
ErrorfMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected