findFunctionActivation searches a hierarchy for the activation which supplies late-bound functions, carrying the match found so far so that a second match can be reported as an error.
(vars Activation, found FunctionActivation)
| 348 | // findFunctionActivation searches a hierarchy for the activation which supplies late-bound |
| 349 | // functions, carrying the match found so far so that a second match can be reported as an error. |
| 350 | func findFunctionActivation(vars Activation, found FunctionActivation) (FunctionActivation, error) { |
| 351 | if vars == nil { |
| 352 | return found, nil |
| 353 | } |
| 354 | switch a := vars.(type) { |
| 355 | case *mapActivation: |
| 356 | // A default activation only supplies functions when it was created for that purpose. |
| 357 | if a.functions != nil { |
| 358 | if found != nil { |
| 359 | return nil, errNestedFunctionActivation |
| 360 | } |
| 361 | found = a |
| 362 | } |
| 363 | return findFunctionActivation(a.parent, found) |
| 364 | case *hierarchicalActivation: |
| 365 | // Both scopes are caller-supplied, so both must be searched. |
| 366 | found, err := findFunctionActivation(a.parent, found) |
| 367 | if err != nil { |
| 368 | return nil, err |
| 369 | } |
| 370 | return findFunctionActivation(a.child, found) |
| 371 | case *partActivation: |
| 372 | // The wrapped activation is not reachable via Parent. |
| 373 | return findFunctionActivation(a.Activation, found) |
| 374 | default: |
| 375 | // An implementation supplied by the caller is responsible for the scopes it contains, |
| 376 | // so its parents are not searched. |
| 377 | if fa, isFunc := vars.(FunctionActivation); isFunc { |
| 378 | if found != nil { |
| 379 | return nil, errNestedFunctionActivation |
| 380 | } |
| 381 | return fa, nil |
| 382 | } |
| 383 | return findFunctionActivation(vars.Parent(), found) |
| 384 | } |
| 385 | } |
no test coverage detected