Decoder bug with complex lists and annotated structures
- Dominant language
- Go
- Stars
- 5.8k
- Forks
- 657
- Avg merge
- 20h 36m
- Merged PRs (30d)
- 6
Description
### HCL Template
Append the following to `decoder_test.go`:
```go
func TestComplexListWithAnnotatedStructs(t *testing.T) {
type KeyValue struct {
Key string `hcl:"key"`
Value string `hcl:"value"`
}
type List struct {
Items []KeyValue `hcl:"item"`
}
list := List{}
err := Unmarshal([]byte(`
item {
key = "key1"
value = "value1"
}
item {
key = "key2"
value = "value2"
}
`), &list)
assert.NoError(t, err, "No error parsing")
assert.Equal(t, 2, len(list.Items), "List has 2 items")
fmt.Println(list.Items)
}
```
### Expected behavior
I expect to get two `KeyValue` structures in `list.Items`:
```
{Key: "key1", Value: "value1"}
{Key: "key2", Value: "value2"}
```
### Actual behavior
Instead I get four:
```
{Key: "Key1", Value: ""}
{Key: "", Value: "value1"}
{Key: "Key2", Value: ""}
{Key: "", Value: "value2"}
```
### Steps to reproduce
1. Append the test to `decoder_test.go`.
2. Run `go test -run TestComplexListWithAnnotatedStructs`
3. Test failure.
Thanks for your time.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by appending the supplied test to decoder_test.go and run go test -run TestComplexListWithAnnotatedStructs. Trace the Unmarshal entry point to understand how the annotated list blocks are decoded. Done means the test passes and list.Items contains two KeyValue structures with the expected keys and values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100