Skip to content

Commit 6a495c8

Browse files
committed
fixupBody missing MissingItemRange
When blocktoattr.fixupBody returned its content, the value for `MissingItemRange` was omitted, losing the diagnostic Subject.
1 parent af68a1e commit 6a495c8

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

internal/lang/blocktoattr/fixup.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ func (b *fixupBody) fixupContent(content *hcl.BodyContent) *hcl.BodyContent {
137137
NameRange: blocks[0].TypeRange,
138138
}
139139
}
140+
141+
ret.MissingItemRange = b.MissingItemRange()
140142
return &ret
141143
}
142144

internal/lang/blocktoattr/fixup_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,46 @@ container {
360360
}),
361361
}),
362362
},
363+
364+
"missing nested block items": {
365+
src: `
366+
container {
367+
foo {
368+
bar = "one"
369+
}
370+
}
371+
`,
372+
schema: &configschema.Block{
373+
BlockTypes: map[string]*configschema.NestedBlock{
374+
"container": {
375+
Nesting: configschema.NestingList,
376+
MinItems: 2,
377+
Block: configschema.Block{
378+
Attributes: map[string]*configschema.Attribute{
379+
"foo": {
380+
Type: cty.List(cty.Object(map[string]cty.Type{
381+
"bar": cty.String,
382+
})),
383+
Optional: true,
384+
},
385+
},
386+
},
387+
},
388+
},
389+
},
390+
want: cty.ObjectVal(map[string]cty.Value{
391+
"container": cty.ListVal([]cty.Value{
392+
cty.ObjectVal(map[string]cty.Value{
393+
"foo": cty.ListVal([]cty.Value{
394+
cty.ObjectVal(map[string]cty.Value{
395+
"bar": cty.StringVal("baz"),
396+
}),
397+
}),
398+
}),
399+
}),
400+
}),
401+
wantErrs: true,
402+
},
363403
}
364404

365405
ctx := &hcl.EvalContext{
@@ -398,6 +438,14 @@ container {
398438
if !diags.HasErrors() {
399439
t.Errorf("succeeded, but want error\ngot: %#v", got)
400440
}
441+
442+
// check that our wrapped body returns the correct context by
443+
// verifying the Subject is valid.
444+
for _, d := range diags {
445+
if d.Subject.Filename == "" {
446+
t.Errorf("empty diagnostic subject: %#v", d.Subject)
447+
}
448+
}
401449
return
402450
}
403451

0 commit comments

Comments
 (0)