| 123 | } |
| 124 | |
| 125 | func (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 | |
| 160 | func (v *Checker) reset(config *conf.Config) { |
| 161 | if v.needsReset { |