From fd77e56fd6a348d16706d661c2572f94e1106bbb Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Tue, 16 Oct 2018 14:55:57 -0700 Subject: [PATCH] lookup will return a tuple type when passed an object --- lang/funcs/collection.go | 14 ++++++-------- lang/funcs/collection_test.go | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lang/funcs/collection.go b/lang/funcs/collection.go index b3f0f0927..68c2e12ee 100644 --- a/lang/funcs/collection.go +++ b/lang/funcs/collection.go @@ -513,11 +513,11 @@ var LookupFunc = function.New(&function.Spec{ // return the default type return args[2].Type(), nil } - return cty.DynamicPseudoType, fmt.Errorf("the given object has no attribute %q", key) + return cty.DynamicPseudoType, function.NewArgErrorf(0, "the given object has no attribute %q", key) case ty.IsMapType(): return ty.ElementType(), nil default: - return cty.NilType, fmt.Errorf("lookup() requires a map as the first argument") + return cty.NilType, function.NewArgErrorf(0, "lookup() requires a map as the first argument") } }, Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { @@ -878,11 +878,7 @@ var ValuesFunc = function.New(&function.Spec{ for _, v := range ty.AttributeTypes() { tys = append(tys, v) } - retType, _ := convert.UnifyUnsafe(tys) - if retType == cty.NilType { - return cty.NilType, fmt.Errorf("all arguments must have the same type") - } - return cty.List(retType), nil + return cty.Tuple(tys), nil } return cty.NilType, fmt.Errorf("values() requires a map as the first argument") }, @@ -918,10 +914,12 @@ var ValuesFunc = function.New(&function.Spec{ } } + if retType.IsTupleType() { + return cty.TupleVal(values), nil + } if len(values) == 0 { return cty.ListValEmpty(retType.ElementType()), nil } - return cty.ListVal(values), nil }, }) diff --git a/lang/funcs/collection_test.go b/lang/funcs/collection_test.go index 5078631e2..b04d01d43 100644 --- a/lang/funcs/collection_test.go +++ b/lang/funcs/collection_test.go @@ -1983,7 +1983,7 @@ func TestValues(t *testing.T) { "hello": cty.StringVal("world"), "what's": cty.StringVal("up"), }), - cty.ListVal([]cty.Value{ + cty.TupleVal([]cty.Value{ cty.StringVal("world"), cty.StringVal("up"), }),