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 {
|
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():
|
case expandVal.Type().IsTupleType() || expandVal.Type().IsListType() || expandVal.Type().IsSetType():
|
||||||
if expandVal.IsNull() {
|
if expandVal.IsNull() {
|
||||||
diags = append(diags, &hcl.Diagnostic{
|
diags = append(diags, &hcl.Diagnostic{
|
||||||
@ -406,22 +420,39 @@ func (e *FunctionCallExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
|
|||||||
} else {
|
} else {
|
||||||
param = varParam
|
param = varParam
|
||||||
}
|
}
|
||||||
argExpr := e.Args[i]
|
|
||||||
|
|
||||||
// TODO: we should also unpick a PathError here and show the
|
// this can happen if an argument is (incorrectly) null.
|
||||||
// path to the deep value where the error was detected.
|
if i > len(e.Args)-1 {
|
||||||
diags = append(diags, &hcl.Diagnostic{
|
diags = append(diags, &hcl.Diagnostic{
|
||||||
Severity: hcl.DiagError,
|
Severity: hcl.DiagError,
|
||||||
Summary: "Invalid function argument",
|
Summary: "Invalid function argument",
|
||||||
Detail: fmt.Sprintf(
|
Detail: fmt.Sprintf(
|
||||||
"Invalid value for %q parameter: %s.",
|
"Invalid value for %q parameter: %s.",
|
||||||
param.Name, err,
|
param.Name, err,
|
||||||
),
|
),
|
||||||
Subject: argExpr.StartRange().Ptr(),
|
Subject: args[len(params)].StartRange().Ptr(),
|
||||||
Context: e.Range().Ptr(),
|
Context: e.Range().Ptr(),
|
||||||
Expression: argExpr,
|
Expression: e,
|
||||||
EvalContext: ctx,
|
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:
|
default:
|
||||||
diags = append(diags, &hcl.Diagnostic{
|
diags = append(diags, &hcl.Diagnostic{
|
||||||
|
@ -312,6 +312,31 @@ upper(
|
|||||||
cty.DynamicVal,
|
cty.DynamicVal,
|
||||||
1, // too many function arguments
|
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,
|
nil,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user