Merge pull request #386 from hashicorp/mildwonkey/b-null-seq-panic
hclsyntax: address multiple issues with sequences (...)
This commit is contained in:
commit
47e2447d3f
@ -260,6 +260,20 @@ func (e *FunctionCallExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
|
||||
}
|
||||
|
||||
switch {
|
||||
case expandVal.Type().Equals(cty.DynamicPseudoType):
|
||||
if expandVal.IsNull() {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "Invalid expanding argument value",
|
||||
Detail: "The expanding argument (indicated by ...) must not be null.",
|
||||
Subject: expandExpr.Range().Ptr(),
|
||||
Context: e.Range().Ptr(),
|
||||
Expression: expandExpr,
|
||||
EvalContext: ctx,
|
||||
})
|
||||
return cty.DynamicVal, diags
|
||||
}
|
||||
return cty.DynamicVal, diags
|
||||
case expandVal.Type().IsTupleType() || expandVal.Type().IsListType() || expandVal.Type().IsSetType():
|
||||
if expandVal.IsNull() {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
@ -406,22 +420,39 @@ func (e *FunctionCallExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
|
||||
} else {
|
||||
param = varParam
|
||||
}
|
||||
argExpr := e.Args[i]
|
||||
|
||||
// TODO: we should also unpick a PathError here and show the
|
||||
// path to the deep value where the error was detected.
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "Invalid function argument",
|
||||
Detail: fmt.Sprintf(
|
||||
"Invalid value for %q parameter: %s.",
|
||||
param.Name, err,
|
||||
),
|
||||
Subject: argExpr.StartRange().Ptr(),
|
||||
Context: e.Range().Ptr(),
|
||||
Expression: argExpr,
|
||||
EvalContext: ctx,
|
||||
})
|
||||
// this can happen if an argument is (incorrectly) null.
|
||||
if i > len(e.Args)-1 {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "Invalid function argument",
|
||||
Detail: fmt.Sprintf(
|
||||
"Invalid value for %q parameter: %s.",
|
||||
param.Name, err,
|
||||
),
|
||||
Subject: args[len(params)].StartRange().Ptr(),
|
||||
Context: e.Range().Ptr(),
|
||||
Expression: e,
|
||||
EvalContext: ctx,
|
||||
})
|
||||
} else {
|
||||
argExpr := e.Args[i]
|
||||
|
||||
// TODO: we should also unpick a PathError here and show the
|
||||
// path to the deep value where the error was detected.
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "Invalid function argument",
|
||||
Detail: fmt.Sprintf(
|
||||
"Invalid value for %q parameter: %s.",
|
||||
param.Name, err,
|
||||
),
|
||||
Subject: argExpr.StartRange().Ptr(),
|
||||
Context: e.Range().Ptr(),
|
||||
Expression: argExpr,
|
||||
EvalContext: ctx,
|
||||
})
|
||||
}
|
||||
|
||||
default:
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
|
@ -312,6 +312,31 @@ upper(
|
||||
cty.DynamicVal,
|
||||
1, // too many function arguments
|
||||
},
|
||||
{
|
||||
`concat([1, null]...)`,
|
||||
&hcl.EvalContext{
|
||||
Functions: map[string]function.Function{
|
||||
"concat": stdlib.ConcatFunc,
|
||||
},
|
||||
},
|
||||
cty.DynamicVal,
|
||||
1, // argument cannot be null
|
||||
},
|
||||
{
|
||||
`concat(var.unknownlist...)`,
|
||||
&hcl.EvalContext{
|
||||
Functions: map[string]function.Function{
|
||||
"concat": stdlib.ConcatFunc,
|
||||
},
|
||||
Variables: map[string]cty.Value{
|
||||
"var": cty.ObjectVal(map[string]cty.Value{
|
||||
"unknownlist": cty.UnknownVal(cty.DynamicPseudoType),
|
||||
}),
|
||||
},
|
||||
},
|
||||
cty.DynamicVal,
|
||||
0,
|
||||
},
|
||||
{
|
||||
`[]`,
|
||||
nil,
|
||||
|
Loading…
Reference in New Issue
Block a user