TestLateBoundFunctionResolverTraversal asserts that resolving a late-bound function visits each activation scope at most once, regardless of how deeply the call site is nested inside comprehensions. The bindings are located once when the evaluation begins, so a call site performs a single lookup no
(t *testing.T)
| 6699 | // a scope whose Parent points back at the enclosing frame rather than at the next link in the |
| 6700 | // chain, so a walk which follows that pointer re-visits every ancestor once per level. |
| 6701 | func TestLateBoundFunctionResolverTraversal(t *testing.T) { |
| 6702 | env := lateBoundComprehensionEnv(t) |
| 6703 | for _, depth := range []int{1, 2, 4, 8, 12} { |
| 6704 | t.Run(fmt.Sprintf("depth %d", depth), func(t *testing.T) { |
| 6705 | expr := nestedComprehension(depth) |
| 6706 | ast, iss := env.Compile(expr) |
| 6707 | if iss.Err() != nil { |
| 6708 | t.Fatalf("Compile(%q) failed: %v", expr, iss.Err()) |
| 6709 | } |
| 6710 | prg, err := env.Program(ast) |
| 6711 | if err != nil { |
| 6712 | t.Fatalf("Program() failed: %v", err) |
| 6713 | } |
| 6714 | root := &countingActivation{Activation: NoVars()} |
| 6715 | _, _, err = prg.Eval(root) |
| 6716 | if err == nil || !strings.Contains(err.Error(), "no such overload: inc") { |
| 6717 | t.Fatalf("Eval() error = %v, wanted 'no such overload: inc'", err) |
| 6718 | } |
| 6719 | // The innermost expression is evaluated exactly once, so the root is visited once. |
| 6720 | if root.calls != 1 { |
| 6721 | t.Errorf("resolution reached the root activation %d times at depth %d, wanted 1", |
| 6722 | root.calls, depth) |
| 6723 | } |
| 6724 | }) |
| 6725 | } |
| 6726 | } |
| 6727 | |
| 6728 | // TestLateBoundFunctionSingleActivation covers the requirement that only one activation in a |
| 6729 | // hierarchy supplies late-bound function implementations. Layering them would make the bindings |
nothing calls this directly
no test coverage detected