Fix panic when setting uint from int value
diff --git a/mapstructure.go b/mapstructure.go index 11bde03..8c05dd9 100644 --- a/mapstructure.go +++ b/mapstructure.go
@@ -137,7 +137,7 @@ if valKind == reflect.Int { val.SetInt(dataVal.Int()) } else { - val.SetUint(uint64(dataVal.Uint())) + val.SetUint(uint64(dataVal.Int())) } case reflect.Uint: if valKind == reflect.Int {
diff --git a/mapstructure_test.go b/mapstructure_test.go index 453fc56..945e5d8 100644 --- a/mapstructure_test.go +++ b/mapstructure_test.go
@@ -5,6 +5,7 @@ type Basic struct { Vstring string Vint int + Vuint uint Vbool bool Vextra string vsilent bool @@ -44,6 +45,7 @@ input := map[string]interface{}{ "vstring": "foo", "vint": 42, + "Vuint": 42, "vbool": true, "vsilent": true, "vdata": 42, @@ -64,6 +66,10 @@ t.Errorf("vint value should be 42: %#v", result.Vint) } + if result.Vuint != 42 { + t.Errorf("vuint value should be 42: %#v", result.Vuint) + } + if result.Vbool != true { t.Errorf("vbool value should be true: %#v", result.Vbool) }