Fix typeSwitchVar warnings (#243)

Fixes #242
This commit is contained in:
Veselkov Konstantin
2018-10-01 00:58:32 +04:00
committed by Thomas Pelletier
parent 78b76feda6
commit 81a861c69d
2 changed files with 12 additions and 16 deletions
+4 -4
View File
@@ -530,20 +530,20 @@ func (d *Decoder) valueFromToml(mtype reflect.Type, tval interface{}) (reflect.V
return d.unwrapPointer(mtype, tval)
}
switch tval.(type) {
switch t := tval.(type) {
case *Tree:
if isTree(mtype) {
return d.valueFromTree(mtype, tval.(*Tree))
return d.valueFromTree(mtype, t)
}
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to a tree", tval, tval)
case []*Tree:
if isTreeSlice(mtype) {
return d.valueFromTreeSlice(mtype, tval.([]*Tree))
return d.valueFromTreeSlice(mtype, t)
}
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to trees", tval, tval)
case []interface{}:
if isOtherSlice(mtype) {
return d.valueFromOtherSlice(mtype, tval.([]interface{}))
return d.valueFromOtherSlice(mtype, t)
}
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to a slice", tval, tval)
default:
+8 -12
View File
@@ -215,17 +215,15 @@ func (t *Tree) SetPathWithOptions(keys []string, opts SetOptions, value interfac
var toInsert interface{}
switch value.(type) {
switch v := value.(type) {
case *Tree:
tt := value.(*Tree)
tt.comment = opts.Comment
v.comment = opts.Comment
toInsert = value
case []*Tree:
toInsert = value
case *tomlValue:
tt := value.(*tomlValue)
tt.comment = opts.Comment
toInsert = tt
v.comment = opts.Comment
toInsert = v
default:
toInsert = &tomlValue{value: value, comment: opts.Comment, commented: opts.Commented, multiline: opts.Multiline}
}
@@ -278,17 +276,15 @@ func (t *Tree) SetPathWithComment(keys []string, comment string, commented bool,
var toInsert interface{}
switch value.(type) {
switch v := value.(type) {
case *Tree:
tt := value.(*Tree)
tt.comment = comment
v.comment = comment
toInsert = value
case []*Tree:
toInsert = value
case *tomlValue:
tt := value.(*tomlValue)
tt.comment = comment
toInsert = tt
v.comment = comment
toInsert = v
default:
toInsert = &tomlValue{value: value, comment: comment, commented: commented}
}