diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_ops.go')
-rw-r--r-- | vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_ops.go | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_ops.go b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_ops.go index 9a5da04..7f59f1a 100644 --- a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_ops.go +++ b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_ops.go | |||
@@ -129,8 +129,8 @@ type BinaryOpExpr struct { | |||
129 | } | 129 | } |
130 | 130 | ||
131 | func (e *BinaryOpExpr) walkChildNodes(w internalWalkFunc) { | 131 | func (e *BinaryOpExpr) walkChildNodes(w internalWalkFunc) { |
132 | e.LHS = w(e.LHS).(Expression) | 132 | w(e.LHS) |
133 | e.RHS = w(e.RHS).(Expression) | 133 | w(e.RHS) |
134 | } | 134 | } |
135 | 135 | ||
136 | func (e *BinaryOpExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) { | 136 | func (e *BinaryOpExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) { |
@@ -149,21 +149,25 @@ func (e *BinaryOpExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) | |||
149 | lhsVal, err := convert.Convert(givenLHSVal, lhsParam.Type) | 149 | lhsVal, err := convert.Convert(givenLHSVal, lhsParam.Type) |
150 | if err != nil { | 150 | if err != nil { |
151 | diags = append(diags, &hcl.Diagnostic{ | 151 | diags = append(diags, &hcl.Diagnostic{ |
152 | Severity: hcl.DiagError, | 152 | Severity: hcl.DiagError, |
153 | Summary: "Invalid operand", | 153 | Summary: "Invalid operand", |
154 | Detail: fmt.Sprintf("Unsuitable value for left operand: %s.", err), | 154 | Detail: fmt.Sprintf("Unsuitable value for left operand: %s.", err), |
155 | Subject: e.LHS.Range().Ptr(), | 155 | Subject: e.LHS.Range().Ptr(), |
156 | Context: &e.SrcRange, | 156 | Context: &e.SrcRange, |
157 | Expression: e.LHS, | ||
158 | EvalContext: ctx, | ||
157 | }) | 159 | }) |
158 | } | 160 | } |
159 | rhsVal, err := convert.Convert(givenRHSVal, rhsParam.Type) | 161 | rhsVal, err := convert.Convert(givenRHSVal, rhsParam.Type) |
160 | if err != nil { | 162 | if err != nil { |
161 | diags = append(diags, &hcl.Diagnostic{ | 163 | diags = append(diags, &hcl.Diagnostic{ |
162 | Severity: hcl.DiagError, | 164 | Severity: hcl.DiagError, |
163 | Summary: "Invalid operand", | 165 | Summary: "Invalid operand", |
164 | Detail: fmt.Sprintf("Unsuitable value for right operand: %s.", err), | 166 | Detail: fmt.Sprintf("Unsuitable value for right operand: %s.", err), |
165 | Subject: e.RHS.Range().Ptr(), | 167 | Subject: e.RHS.Range().Ptr(), |
166 | Context: &e.SrcRange, | 168 | Context: &e.SrcRange, |
169 | Expression: e.RHS, | ||
170 | EvalContext: ctx, | ||
167 | }) | 171 | }) |
168 | } | 172 | } |
169 | 173 | ||
@@ -178,10 +182,12 @@ func (e *BinaryOpExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) | |||
178 | if err != nil { | 182 | if err != nil { |
179 | diags = append(diags, &hcl.Diagnostic{ | 183 | diags = append(diags, &hcl.Diagnostic{ |
180 | // FIXME: This diagnostic is useless. | 184 | // FIXME: This diagnostic is useless. |
181 | Severity: hcl.DiagError, | 185 | Severity: hcl.DiagError, |
182 | Summary: "Operation failed", | 186 | Summary: "Operation failed", |
183 | Detail: fmt.Sprintf("Error during operation: %s.", err), | 187 | Detail: fmt.Sprintf("Error during operation: %s.", err), |
184 | Subject: &e.SrcRange, | 188 | Subject: &e.SrcRange, |
189 | Expression: e, | ||
190 | EvalContext: ctx, | ||
185 | }) | 191 | }) |
186 | return cty.UnknownVal(e.Op.Type), diags | 192 | return cty.UnknownVal(e.Op.Type), diags |
187 | } | 193 | } |
@@ -206,7 +212,7 @@ type UnaryOpExpr struct { | |||
206 | } | 212 | } |
207 | 213 | ||
208 | func (e *UnaryOpExpr) walkChildNodes(w internalWalkFunc) { | 214 | func (e *UnaryOpExpr) walkChildNodes(w internalWalkFunc) { |
209 | e.Val = w(e.Val).(Expression) | 215 | w(e.Val) |
210 | } | 216 | } |
211 | 217 | ||
212 | func (e *UnaryOpExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) { | 218 | func (e *UnaryOpExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) { |
@@ -219,11 +225,13 @@ func (e *UnaryOpExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) { | |||
219 | val, err := convert.Convert(givenVal, param.Type) | 225 | val, err := convert.Convert(givenVal, param.Type) |
220 | if err != nil { | 226 | if err != nil { |
221 | diags = append(diags, &hcl.Diagnostic{ | 227 | diags = append(diags, &hcl.Diagnostic{ |
222 | Severity: hcl.DiagError, | 228 | Severity: hcl.DiagError, |
223 | Summary: "Invalid operand", | 229 | Summary: "Invalid operand", |
224 | Detail: fmt.Sprintf("Unsuitable value for unary operand: %s.", err), | 230 | Detail: fmt.Sprintf("Unsuitable value for unary operand: %s.", err), |
225 | Subject: e.Val.Range().Ptr(), | 231 | Subject: e.Val.Range().Ptr(), |
226 | Context: &e.SrcRange, | 232 | Context: &e.SrcRange, |
233 | Expression: e.Val, | ||
234 | EvalContext: ctx, | ||
227 | }) | 235 | }) |
228 | } | 236 | } |
229 | 237 | ||
@@ -238,10 +246,12 @@ func (e *UnaryOpExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) { | |||
238 | if err != nil { | 246 | if err != nil { |
239 | diags = append(diags, &hcl.Diagnostic{ | 247 | diags = append(diags, &hcl.Diagnostic{ |
240 | // FIXME: This diagnostic is useless. | 248 | // FIXME: This diagnostic is useless. |
241 | Severity: hcl.DiagError, | 249 | Severity: hcl.DiagError, |
242 | Summary: "Operation failed", | 250 | Summary: "Operation failed", |
243 | Detail: fmt.Sprintf("Error during operation: %s.", err), | 251 | Detail: fmt.Sprintf("Error during operation: %s.", err), |
244 | Subject: &e.SrcRange, | 252 | Subject: &e.SrcRange, |
253 | Expression: e, | ||
254 | EvalContext: ctx, | ||
245 | }) | 255 | }) |
246 | return cty.UnknownVal(e.Op.Type), diags | 256 | return cty.UnknownVal(e.Op.Type), diags |
247 | } | 257 | } |