From 1a9d040ea4711ef817320d0d096ba57e7ea25540 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 11 Aug 2014 21:33:44 -0700 Subject: [PATCH] Support Elem on lists --- decoder.go | 4 ++++ hcl/object.go | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/decoder.go b/decoder.go index 0127c37..2534f47 100644 --- a/decoder.go +++ b/decoder.go @@ -198,6 +198,10 @@ func (d *decoder) decodeMap(name string, o *hcl.Object, result reflect.Value) er // Go through each element and decode it. current := o for current != nil { + if current.Value == nil { + continue + } + m := current.Value.([]*hcl.Object) for _, o := range m { // Make the field name diff --git a/hcl/object.go b/hcl/object.go index 3c321db..aa58081 100644 --- a/hcl/object.go +++ b/hcl/object.go @@ -69,12 +69,14 @@ func (o *Object) Elem(expand bool) []*Object { return result } - switch o.Type { - case ValueTypeObject: - if o.Value == nil { - return nil - } + if o.Value == nil { + return nil + } + switch o.Type { + case ValueTypeList: + return o.Value.([]*Object) + case ValueTypeObject: return o.Value.([]*Object) }