checkLoadedASTDepth guards ASTs that enter through the proto conversion helpers (ParsedExprToAst / CheckedExprToAst) against nesting deeper than the parser's recursion limit. Those entry points bypass the parser, so without this check a deeply nested loaded AST could exhaust the Go stack during late
(a *ast.AST)
| 104 | // Embedders that fully control their AST inputs can skip this by building the AST through the |
| 105 | // common/ast package directly instead of these conversion helpers. |
| 106 | func checkLoadedASTDepth(a *ast.AST) error { |
| 107 | if ast.ExceedsDepth(a, defaultMaxASTDepth) { |
| 108 | return fmt.Errorf("input exceeds maximum expression nesting depth: %d", defaultMaxASTDepth) |
| 109 | } |
| 110 | return nil |
| 111 | } |
| 112 | |
| 113 | // AstToParsedExpr converts an Ast to an protobuf ParsedExpr value. |
| 114 | func AstToParsedExpr(a *Ast) (*exprpb.ParsedExpr, error) { |
no test coverage detected