(ctx *hcl.EvalContext)
| 219 | } |
| 220 | |
| 221 | func (e *FunctionCallExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) { |
| 222 | var diags hcl.Diagnostics |
| 223 | |
| 224 | var f function.Function |
| 225 | exists := false |
| 226 | hasNonNilMap := false |
| 227 | thisCtx := ctx |
| 228 | for thisCtx != nil { |
| 229 | if thisCtx.Functions == nil { |
| 230 | thisCtx = thisCtx.Parent() |
| 231 | continue |
| 232 | } |
| 233 | hasNonNilMap = true |
| 234 | f, exists = thisCtx.Functions[e.Name] |
| 235 | if exists { |
| 236 | break |
| 237 | } |
| 238 | thisCtx = thisCtx.Parent() |
| 239 | } |
| 240 | |
| 241 | if !exists { |
| 242 | if !hasNonNilMap { |
| 243 | return cty.DynamicVal, hcl.Diagnostics{ |
| 244 | { |
| 245 | Severity: hcl.DiagError, |
| 246 | Summary: "Function calls not allowed", |
| 247 | Detail: "Functions may not be called here.", |
| 248 | Subject: e.Range().Ptr(), |
| 249 | Expression: e, |
| 250 | EvalContext: ctx, |
| 251 | }, |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | extraUnknown := &functionCallUnknown{ |
| 256 | name: e.Name, |
| 257 | } |
| 258 | |
| 259 | // For historical reasons, we represent namespaced function names |
| 260 | // as strings with :: separating the names. If this was an attempt |
| 261 | // to call a namespaced function then we'll try to distinguish |
| 262 | // between an invalid namespace or an invalid name within a valid |
| 263 | // namespace in order to give the user better feedback about what |
| 264 | // is wrong. |
| 265 | // |
| 266 | // The parser guarantees that a function name will always |
| 267 | // be a series of valid identifiers separated by "::" with no |
| 268 | // other content, so we can be relatively unforgiving in our processing |
| 269 | // here. |
| 270 | if sepIdx := strings.LastIndex(e.Name, "::"); sepIdx != -1 { |
| 271 | namespace := e.Name[:sepIdx+2] |
| 272 | name := e.Name[sepIdx+2:] |
| 273 | |
| 274 | avail := make([]string, 0, len(ctx.Functions)) |
| 275 | for availName := range ctx.Functions { |
| 276 | if strings.HasPrefix(availName, namespace) { |
| 277 | avail = append(avail, availName) |
| 278 | } |
nothing calls this directly
no test coverage detected