fix(parse): do not over-promote branch-local variables to params
If/else arms that all bind a local (e.g. # llm key/url/mdl/nm) no longer leak it into constructor params. This fixes the missing `key` error in llm.create and restores the agent/llm gold tests. Adds a regression test.
This commit is contained in:
1 parent
1415aee08f
commit
d99b275336
2 files changed
+45
No files matched your search
@@ -13,6 +13,7 @@
|
||||
|
||||
### Fixed
|
||||
|
||||
- **分支内共同局部变量**:if/else 各臂都赋值的局部变量不再被误提升为必选形参;修复 `# llm` 构造器无端要求 `key`,恢复 agent/llm/ext 全量测试。新增 `branch_else_common_local_is_not_a_param` 回归测试。
|
||||
- **外联临时脚本路径**:入口目录为相对路径时,脚本参数现在使用绝对路径,避免 `tests/lib/tests/lib/...` 双拼接。
|
||||
- **外联失败可观测**:解释器不存在时进入 `invoke` 记录,`run` 仍报错;view 显示 stderr / exit / ms。
|
||||
|
||||
|
||||
@@ -2002,6 +2002,8 @@ fn collect_names_needing_input(
|
||||
}
|
||||
}
|
||||
Stmt::Branch { arms, .. } => {
|
||||
let has_else = arms.iter().any(|a| a.condition.is_none());
|
||||
let mut common: Option<std::collections::HashSet<String>> = None;
|
||||
for a in arms {
|
||||
if let Some(c) = &a.condition {
|
||||
let mut reads = std::collections::HashSet::new();
|
||||
@@ -2020,6 +2022,17 @@ fn collect_names_needing_input(
|
||||
loop_items,
|
||||
assign_decls,
|
||||
);
|
||||
if has_else {
|
||||
common = Some(match common {
|
||||
None => arm_bound,
|
||||
Some(prev) => prev.intersection(&arm_bound).cloned().collect(),
|
||||
});
|
||||
}
|
||||
}
|
||||
if let Some(c) = common {
|
||||
for n in c {
|
||||
bound.insert(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
Stmt::While {
|
||||
@@ -2574,6 +2587,37 @@ Candidates may include lexical `score`.
|
||||
other => panic!("expected code assign, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn branch_else_common_local_is_not_a_param() {
|
||||
let src = r#"# main
|
||||
|
||||
## f
|
||||
+ `a`=None
|
||||
|
||||
1. `a`
|
||||
**k = a**
|
||||
2. *
|
||||
**k = None**
|
||||
|
||||
| x |
|
||||
|---|
|
||||
| `k` |
|
||||
"#;
|
||||
let m = parse_source(src).unwrap();
|
||||
let f = m
|
||||
.functions
|
||||
.iter()
|
||||
.flat_map(|outer| outer.children.iter())
|
||||
.find(|f| f.name == "f")
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
f.params.iter().map(|p| p.name.as_str()).collect::<Vec<_>>(),
|
||||
["a"],
|
||||
"{:?}",
|
||||
f.params
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 核心表面构造注册表(T1.3)——`(id, Markdown 外形)`。
|
||||
|
||||
Reference in new issue
Block a user