diff --git a/decoder.go b/decoder.go index 6a4bb76..d578b3a 100644 --- a/decoder.go +++ b/decoder.go @@ -323,9 +323,9 @@ func (d *decoder) decodeString(name string, raw ast.Node, result reflect.Value) switch n.Type { case ast.ValueTypeInt: result.Set(reflect.ValueOf( - strconv.FormatInt(int64(n.Value.(int)), 10))) + strconv.FormatInt(int64(n.Value.(int)), 10)).Convert(result.Type())) case ast.ValueTypeString: - result.Set(reflect.ValueOf(n.Value.(string))) + result.Set(reflect.ValueOf(n.Value.(string)).Convert(result.Type())) default: return fmt.Errorf("%s: unknown type to string: %s", name, n.Type) } diff --git a/decoder_test.go b/decoder_test.go index 1272511..9ea9621 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -188,9 +188,11 @@ func TestDecode_structureArray(t *testing.T) { // This test is extracted from a failure in Consul (consul.io), // hence the interesting structure naming. + type KeyPolicyType string + type KeyPolicy struct { Prefix string `hcl:",key"` - Policy string + Policy KeyPolicyType } type Policy struct {