From dde4979c490a571d9d9a6016fe791031f57470b8 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Wed, 27 Apr 2022 14:52:03 -0400 Subject: [PATCH] typeexpr: Improve diagnostic for any() constraints Using the any keyword with arguments (e.g. any(string, bool)) is invalid, but any is not technically a "primitive type keyword". This commit corrects the language in the diagnostic and updates the tests. --- internal/typeexpr/get_type.go | 9 ++++++++- internal/typeexpr/get_type_test.go | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/typeexpr/get_type.go b/internal/typeexpr/get_type.go index de5465b997..726326adcc 100644 --- a/internal/typeexpr/get_type.go +++ b/internal/typeexpr/get_type.go @@ -77,13 +77,20 @@ func getType(expr hcl.Expression, constraint bool) (cty.Type, hcl.Diagnostics) { } switch call.Name { - case "bool", "string", "number", "any": + case "bool", "string", "number": return cty.DynamicPseudoType, hcl.Diagnostics{{ Severity: hcl.DiagError, Summary: invalidTypeSummary, Detail: fmt.Sprintf("Primitive type keyword %q does not expect arguments.", call.Name), Subject: &call.ArgsRange, }} + case "any": + return cty.DynamicPseudoType, hcl.Diagnostics{{ + Severity: hcl.DiagError, + Summary: invalidTypeSummary, + Detail: fmt.Sprintf("Type constraint keyword %q does not expect arguments.", call.Name), + Subject: &call.ArgsRange, + }} } if len(call.Arguments) != 1 { diff --git a/internal/typeexpr/get_type_test.go b/internal/typeexpr/get_type_test.go index 0cfb5b39b7..f94ee926a1 100644 --- a/internal/typeexpr/get_type_test.go +++ b/internal/typeexpr/get_type_test.go @@ -104,13 +104,13 @@ func TestGetType(t *testing.T) { `any()`, false, cty.DynamicPseudoType, - `Primitive type keyword "any" does not expect arguments.`, + `Type constraint keyword "any" does not expect arguments.`, }, { `any()`, true, cty.DynamicPseudoType, - `Primitive type keyword "any" does not expect arguments.`, + `Type constraint keyword "any" does not expect arguments.`, }, { `list(string)`,