convert types for type aliases

This commit is contained in:
Mitchell Hashimoto 2014-08-08 16:07:08 -07:00
parent 437eb0d851
commit 0b07544203
2 changed files with 5 additions and 3 deletions

View File

@ -323,9 +323,9 @@ func (d *decoder) decodeString(name string, raw ast.Node, result reflect.Value)
switch n.Type { switch n.Type {
case ast.ValueTypeInt: case ast.ValueTypeInt:
result.Set(reflect.ValueOf( result.Set(reflect.ValueOf(
strconv.FormatInt(int64(n.Value.(int)), 10))) strconv.FormatInt(int64(n.Value.(int)), 10)).Convert(result.Type()))
case ast.ValueTypeString: case ast.ValueTypeString:
result.Set(reflect.ValueOf(n.Value.(string))) result.Set(reflect.ValueOf(n.Value.(string)).Convert(result.Type()))
default: default:
return fmt.Errorf("%s: unknown type to string: %s", name, n.Type) return fmt.Errorf("%s: unknown type to string: %s", name, n.Type)
} }

View File

@ -188,9 +188,11 @@ func TestDecode_structureArray(t *testing.T) {
// This test is extracted from a failure in Consul (consul.io), // This test is extracted from a failure in Consul (consul.io),
// hence the interesting structure naming. // hence the interesting structure naming.
type KeyPolicyType string
type KeyPolicy struct { type KeyPolicy struct {
Prefix string `hcl:",key"` Prefix string `hcl:",key"`
Policy string Policy KeyPolicyType
} }
type Policy struct { type Policy struct {