Skip to content

Commit bc947d5

Browse files
committed
Fix bug in checker with nil config
1 parent eeaac92 commit bc947d5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

checker/checker.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,27 @@ func Check(tree *parser.Tree, config *conf.Config) (t reflect.Type, err error) {
2121
}()
2222

2323
v := &visitor{
24-
types: config.Types,
2524
collections: make([]reflect.Type, 0),
2625
}
26+
if config != nil {
27+
v.types = config.Types
28+
v.expect = config.Expect
29+
}
2730

2831
t = v.visit(tree.Node)
2932

30-
if config.Expect != reflect.Invalid {
31-
switch config.Expect {
33+
if v.expect != reflect.Invalid {
34+
switch v.expect {
3235
case reflect.Int64, reflect.Float64:
3336
if isNumber(t) {
3437
goto okay
3538
}
3639
default:
37-
if t.Kind() == config.Expect {
40+
if t.Kind() == v.expect {
3841
goto okay
3942
}
4043
}
41-
return nil, fmt.Errorf("expected %v, but got %v", config.Expect, t)
44+
return nil, fmt.Errorf("expected %v, but got %v", v.expect, t)
4245
}
4346

4447
okay:
@@ -47,6 +50,7 @@ okay:
4750

4851
type visitor struct {
4952
types conf.TypesTable
53+
expect reflect.Kind
5054
collections []reflect.Type
5155
}
5256

0 commit comments

Comments
 (0)