Skip to content

Commit dc8074e

Browse files
committed
fix: preserve grouped comparisons
1 parent 9387a76 commit dc8074e

5 files changed

Lines changed: 48 additions & 4 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# R14.6 任务报告
2+
3+
## 结论
4+
5+
Linux Action 的大规模级联失败来自函数定义元数据把形参误记为未绑定局部变量。布尔值 `False` 默认参数在调用时被 `ARG_TYPE_UNDEF` 占位遮蔽,最终触发 `UnboundLocalError`。
6+
7+
## 修复
8+
9+
- 从规范化函数声明中提取形参名称。
10+
- 建立未绑定局部变量集合时排除全部形参和 `global` 名称。
11+
- 覆盖顶层函数、带类型注解的方法、`False` 默认值和显式 `True` 覆盖。
12+
- 不新增 VM 指令或调用路径;临时名称集合仅在函数定义时创建并立即释放,调用热路径和持久 RAM 结构不变。
13+
14+
## 验证
15+
16+
- `pikaMain.python3_default_argument_definition_time`:1/1 通过。
17+
- 未绑定局部、作用域邻接和重复参数绑定:3/3 通过。
18+
- `pikaMain.unitTest`:通过,内存峰值 33.65 kB。
19+
- GitHub Action `29616829259` 中原 `stop_on_error` 未绑定错误和 353 个级联失败均已消失;剩余 2 项独立 parser 回归转入 R14.7。
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# R14.7 任务报告
2+
3+
## 结论
4+
5+
链式比较门禁在整条表达式上累计比较运算符,导致 `a < b and b < c` 与 `a < b or c < d` 被误判为不支持的链式比较。
6+
7+
## 修复
8+
9+
- 先确定顶层运算符,再执行链式比较数量检查。
10+
- 顶层为 `and` 或 `or` 时先按现有 AST 递归分组;每个分支仍独立执行链式比较门禁。
11+
- 恢复已有逻辑比较子集,不新增表达式能力;`1 < 2 < 3` 和混合链式比较仍稳定返回语法错误。
12+
- 只调整 parser 现有检查顺序,不新增持久状态、VM 指令、RAM 字段或 runtime 热路径工作。
13+
14+
## 验证
15+
16+
- 逻辑比较、非法链式比较、短路语义及两个原失败集成测试:5/5 通过。
17+
- 隔离 LVGL 和网络后的 Linux default 全量:467/467 通过,耗时 26.194 秒。
18+
- 构建使用宿主 mbedTLS 3 的临时 API 别名;该别名只存在于本地 CMake 配置,没有进入仓库变更。

‎docs/MDTODO/pikapython-syntax-compatibility.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ P0 修复空 import 与 from-import 缺名称在 Suger_import 路径的解析崩
315315

316316
继续解决 [#348](https://github.com/pikasTech/PikaPython/issues/348) 的 VM 性能债务:优化 kwargs 名称恢复中的常量池重复扫描,在不扩大语法、不改变 VM 大架构且不增加常驻 RAM 的前提下完成同机 A/B、default/minimal 资源和语义回归,完成任务后将详细报告写入[任务报告](./details/pikapython-syntax-compatibility/R14.5_Task_Report.md)。
317317

318-
### R14.6 [in_progress]
318+
### R14.6 [completed]
319319

320320
修复 Linux Action 暴露的默认参数名被误记为未绑定局部变量问题,覆盖 False 默认值和方法参数,完成隔离 Linux 回归并确认不扩大语法或 VM 架构,完成任务后将详细报告写入[任务报告](./details/pikapython-syntax-compatibility/R14.6_Task_Report.md)。
321+
322+
### R14.7 [completed]
323+
324+
修复 Linux Action 暴露的逻辑组合比较被链式比较门禁错误拒绝问题,保持非法链式比较稳定拒绝并恢复已有 and/or 条件子集,完成任务后将详细报告写入[任务报告](./details/pikapython-syntax-compatibility/R14.7_Task_Report.md)。

‎port/linux/test/py-test.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ TEST(parser, comparison_and_exception_valid_neighbors) {
313313
"less = 1 < 2\n"
314314
"nested = (1 < 2) == True\n"
315315
"member = 1 in [1]\n"
316+
"both = 1 < 2 and 2 < 3\n"
317+
"either = 3 < 2 or 2 < 3\n"
316318
"try:\n"
317319
" raise\n"
318320
"except:\n"

‎src/PikaParser.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,12 +2000,13 @@ AST* AST_parseStmt(AST* ast, char* sStmt) {
20002000
sRight = Suger_not_in(&buffs, sRight);
20012001
sRight = Suger_is_not(&buffs, sRight);
20022002
char* rightWithoutSubStmt = _remove_sub_stmt(&buffs, sRight);
2003-
if (_countComparisonOperators(rightWithoutSubStmt) > 1) {
2003+
char* operator = Lexer_getOperator(&buffs, rightWithoutSubStmt);
2004+
if (NULL == operator) {
20042005
eResult = PIKA_RES_ERR_SYNTAX_ERROR;
20052006
goto __exit;
20062007
}
2007-
char* operator= Lexer_getOperator(&buffs, rightWithoutSubStmt);
2008-
if (NULL == operator) {
2008+
if (!strEqu(operator, " and ") && !strEqu(operator, " or ") &&
2009+
_countComparisonOperators(rightWithoutSubStmt) > 1) {
20092010
eResult = PIKA_RES_ERR_SYNTAX_ERROR;
20102011
goto __exit;
20112012
}

0 commit comments

Comments
 (0)