Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embedded struct fields are not populated #136

Open
BrianHicks opened this issue Jun 22, 2016 · 3 comments
Open

embedded struct fields are not populated #136

BrianHicks opened this issue Jun 22, 2016 · 3 comments
Labels
v1 Relates to the v1 line of releases

Comments

@BrianHicks
Copy link

Unmarshalling embedded struct fields works in encoding/json but not HCL (as of 5b7dbf7). Here's the code using encoding/json: https://play.golang.org/p/rrXXw7j8VM. The equivalent in HCL follows:

package main

import (
    "fmt"

    "github.com/hashicorp/hcl"
)

type Inner struct {
    Dependencies []string `hcl:"dependencies"`
}

type Outer struct {
    Inner

    Name string `hcl:"name"`
}

func main() {
    x := new(Outer)

    err := hcl.Unmarshal(
        []byte(`
name = "test"
dependencies = ["a", "b", "c"]
`),
        x,
    )

    fmt.Printf("%+v %v\n", x, err)
}

Would this be a contribution y'all are interested in? If you are and you could point me toward a good place to get started, I'd appreciate it :)

@BrianHicks
Copy link
Author

Update: looks like this is possible, but I had to dig through the code:

type Outer struct {
    Inner `hcl:",squash"`
}

I couldn't find any documentation for this, and as above encoding/json does it by default. Was there a rationale for the difference? Either way, happy to contribute documentation. Easier than a code fix. ;)

@apparentlymart apparentlymart added the v1 Relates to the v1 line of releases label Aug 27, 2018
@let4be
Copy link

let4be commented Apr 6, 2020

Was this broken? doesn't seem to work in v2
There is a huge problem with documentation for HCL

panic: invalid hcl field tag kind "squash" on ...

@Alma-media
Copy link

faced the same issue with v2

type Outer struct {
    Inner `hcl:",remain"`
}

works for me 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1 Relates to the v1 line of releases
Projects
None yet
Development

No branches or pull requests

4 participants