diff --git a/hcldec/public_test.go b/hcldec/public_test.go index 79ef710..ed9c10b 100644 --- a/hcldec/public_test.go +++ b/hcldec/public_test.go @@ -86,6 +86,23 @@ func TestDecode(t *testing.T) { cty.NumberIntVal(10), 0, }, + { + "a = 1\n", + ObjectSpec{ + "foo": &DefaultSpec{ + Primary: &AttrSpec{ + Name: "a", + Type: cty.Number, + }, + Default: &LiteralSpec{ + Value: cty.NumberIntVal(10), + }, + }, + }, + nil, + cty.ObjectVal(map[string]cty.Value{"foo": cty.NumberIntVal(1)}), + 0, + }, { "a = \"1\"\n", &AttrSpec{ diff --git a/hcldec/schema.go b/hcldec/schema.go index fff60b1..b57bd96 100644 --- a/hcldec/schema.go +++ b/hcldec/schema.go @@ -14,7 +14,8 @@ func ImpliedSchema(spec Spec) *hcl.BodySchema { // visitSameBodyChildren walks through the spec structure, calling // the given callback for each descendent spec encountered. We are // interested in the specs that reference attributes and blocks. - visit := func(s Spec) { + var visit visitFunc + visit = func(s Spec) { if as, ok := s.(attrSpec); ok { attrs = append(attrs, as.attrSchemata()...) } @@ -22,10 +23,11 @@ func ImpliedSchema(spec Spec) *hcl.BodySchema { if bs, ok := s.(blockSpec); ok { blocks = append(blocks, bs.blockHeaderSchemata()...) } + + s.visitSameBodyChildren(visit) } visit(spec) - spec.visitSameBodyChildren(visit) return &hcl.BodySchema{ Attributes: attrs,