From 0b07544203aeb5a2985932f7f8bafc457c7c806b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 8 Aug 2014 16:07:08 -0700 Subject: [PATCH] convert types for type aliases --- decoder.go | 4 ++-- decoder_test.go | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) 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 {