{"record":{"id":"d84deac2ac36389a","repo":"vitessio/vitess","slug":"bug-tried-to-replace-asttype-on-valuecontaine","errorCode":null,"errorMessage":"[BUG] tried to replace 'ASTType' on 'ValueContainer'","messagePattern":"\\[BUG\\] tried to replace 'ASTType' on 'ValueContainer'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"go/tools/asthelpergen/integration/ast_rewrite.go","lineNumber":450,"sourceCode":"func (a *application) rewriteValueContainer(parent AST, node ValueContainer, replacer replacerFunc) bool {\n\tif a.pre != nil {\n\t\ta.cur.replacer = replacer\n\t\ta.cur.parent = parent\n\t\ta.cur.node = node\n\t\tkontinue := !a.pre(&a.cur)\n\t\tif a.cur.revisit {\n\t\t\ta.cur.revisit = false\n\t\t\treturn a.rewriteAST(parent, a.cur.node, replacer)\n\t\t}\n\t\tif kontinue {\n\t\t\treturn true\n\t\t}\n\t}\n\tif a.collectPaths {\n\t\ta.cur.current.AddStep(uint16(ValueContainerASTType))\n\t}\n\tif !a.rewriteAST(node, node.ASTType, func(newNode, parent AST) {\n\t\tpanic(\"[BUG] tried to replace 'ASTType' on 'ValueContainer'\")\n\t}) {\n\t\treturn false\n\t}\n\tif a.collectPaths {\n\t\ta.cur.current.Pop()\n\t\ta.cur.current.AddStep(uint16(ValueContainerASTImplementationType))\n\t}\n\tif !a.rewriteRefOfLeaf(node, node.ASTImplementationType, func(newNode, parent AST) {\n\t\tpanic(\"[BUG] tried to replace 'ASTImplementationType' on 'ValueContainer'\")\n\t}) {\n\t\treturn false\n\t}\n\tif a.collectPaths {\n\t\ta.cur.current.Pop()\n\t}\n\tif a.post != nil {\n\t\ta.cur.replacer = replacer\n\t\ta.cur.parent = parent","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/tools/asthelpergen/integration/ast_rewrite.go#L432-L468","documentation":"This panic lives inside the generated AST rewriter for the ValueContainer node. The 'ASTType' child of a ValueContainer is structural and must never be rewritten, so the rewrite callback is written to panic '[BUG] tried to replace ASTType on ValueContainer' if the walker ever proposes replacing it. Hitting it means an invariant of the AST rewriting contract is violated — it is always a bug in the rewriter/walker, not in user code.","triggerScenarios":"Running a rewrite pass (rewriteAST) over a ValueContainer node where the replacement logic tries to substitute the node's ASTType child instead of its value or implementation-type children; typically caused by changes to the generated walker or rewrite rules.","commonSituations":"After regenerating sqlparser code (make codegen) following an AST definition change, rewrite passes on type-valued containers start crashing in tests.","solutions":["Inspect the rewrite pass stack trace to find which walker change proposes replacing the ASTType child","Fix the rewrite callback/walker so ASTType children are skipped (not visited as replaceable) and re-run make codegen","Report upstream if it reproduces on unmodified vitess main — it indicates a codegen bug in asthelpergen rewrite generation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Reproduce under test with path collection enabled before merging walker changes\nnode.Rewrite(func(newNode, parent AST) { ... }) // run in a test with collectPaths = true","typeGuard":null,"tryCatchPattern":"func() {\n    defer func() {\n        if r := recover(); r != nil && strings.Contains(fmt.Sprint(r), \"tried to replace 'ASTType'\") {\n            log.Fatalf(\"codegen bug: rewriter touched ASTType child: %v\", r)\n        }\n    }()\n    runRewritePass(node)\n}()","preventionTips":["Never modify ASTType children in rewrite callbacks — only value/implementation children","Re-run make codegen and sqlparser tests after any AST definition change","Treat this panic as a bug report: capture the stack trace and fix the walker, don't work around it in caller code"],"tags":["codegen","go","sqlparser","ast-rewrite","invariant-violation"],"backgroundTag":"ast-rewrite-invariant-violation","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}