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) return d.unwrapPointer(mtype, tval)
} }
switch tval.(type) { switch t := tval.(type) {
case *Tree: case *Tree:
if isTree(mtype) { 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) return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to a tree", tval, tval)
case []*Tree: case []*Tree:
if isTreeSlice(mtype) { 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) return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to trees", tval, tval)
case []interface{}: case []interface{}:
if isOtherSlice(mtype) { 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) return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to a slice", tval, tval)
default: default:
+8 -12
View File
@@ -215,17 +215,15 @@ func (t *Tree) SetPathWithOptions(keys []string, opts SetOptions, value interfac
var toInsert interface{} var toInsert interface{}
switch value.(type) { switch v := value.(type) {
case *Tree: case *Tree:
tt := value.(*Tree) v.comment = opts.Comment
tt.comment = opts.Comment
toInsert = value toInsert = value
case []*Tree: case []*Tree:
toInsert = value toInsert = value
case *tomlValue: case *tomlValue:
tt := value.(*tomlValue) v.comment = opts.Comment
tt.comment = opts.Comment toInsert = v
toInsert = tt
default: default:
toInsert = &tomlValue{value: value, comment: opts.Comment, commented: opts.Commented, multiline: opts.Multiline} 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{} var toInsert interface{}
switch value.(type) { switch v := value.(type) {
case *Tree: case *Tree:
tt := value.(*Tree) v.comment = comment
tt.comment = comment
toInsert = value toInsert = value
case []*Tree: case []*Tree:
toInsert = value toInsert = value
case *tomlValue: case *tomlValue:
tt := value.(*tomlValue) v.comment = comment
tt.comment = comment toInsert = v
toInsert = tt
default: default:
toInsert = &tomlValue{value: value, comment: comment, commented: commented} toInsert = &tomlValue{value: value, comment: comment, commented: commented}
} }