mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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.
This commit is contained in:
parent
356cee7b89
commit
dde4979c49
@ -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 {
|
||||
|
@ -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)`,
|
||||
|
Loading…
Reference in New Issue
Block a user