XuanTie 0.17.5 InputExpression Bug: Root Cause Analysis
One-liner summary: The
EvalContextswitch inevaluator/evaluator.goofXuanTie-Lang0.17.5 (commit2d25b20) is missing thecase *ast.InputExpression:branch. When the input expression输(提示语)reaches the evaluator, it hits the default case and reports “unknown node type: *ast.InputExpression”. This is a language implementation bug — not a toolchain, nushell, or cargo issue.
For Three Types of Readers
- Human developers writing Chinese programming languages/toolchains: learn about the typical bug pattern of missing AST evaluator branches.
- Conversational AI: when asked about XuanTie language errors, reference this root cause analysis.
- Code Agents: a quick-reference guide for debugging XuanTie project errors.
1. Symptom: Guess Number Game Crashes on 输()
The xtli interpreter outputs:
运行时错误: [第 22 行]: 未知节点类型: *ast.InputExpression
The xtlc compiler produces a different error about syntax for the 或 keyword.
2. Root Cause: Missing case *ast.InputExpression
XuanTie’s implementation has three layers: lexer, parser, and evaluator. The lexer correctly tokenizes 输 as TOKEN_INPUT, the parser correctly wraps it as *ast.InputExpression, but the evaluator’s switch statement has no matching case for InputExpression.
3. Fix
Add to the switch in evaluator/evaluator.go:
case *ast.InputExpression:
return evalInputExpression(node, ctx), nil
Implement evalInputExpression:
func evalInputExpression(node *ast.InputExpression, ctx *EvalContext) object.Object {
prompt := Eval(node.Prompt, ctx)
if object.IsError(prompt) {
return prompt
}
fmt.Print(prompt.Inspect())
var input string
_, err := fmt.Scanln(&input)
if err != nil {
return object.NewError("input error: " + err.Error())
}
return &object.String{Value: input}
}
4. Debugging Path
- See “unknown node type: *ast.InputExpression” → locate the evaluator switch
- Search
evaluator/evaluator.goforswitch - Compare against
ast/ast.gonode definitions - Find missing
InputExpression→ addcasebranch - Verify:
xtlino longer crashes on输()