Skip to content

Commit

Permalink
hcldec: ImpliedSchema must visit deep specs
Browse files Browse the repository at this point in the history
Previously, due to a bug, it was only visiting the first two levels of
specifications, missing anything referenced at lower levels.
  • Loading branch information
apparentlymart committed Oct 3, 2017
1 parent a4ee718 commit cc215b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions hcldec/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 4 additions & 2 deletions hcldec/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ 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()...)
}

if bs, ok := s.(blockSpec); ok {
blocks = append(blocks, bs.blockHeaderSchemata()...)
}

s.visitSameBodyChildren(visit)
}

visit(spec)
spec.visitSameBodyChildren(visit)

return &hcl.BodySchema{
Attributes: attrs,
Expand Down

0 comments on commit cc215b6

Please sign in to comment.