fix(tpc): 返回 fail-fast 判据改为源码层面——显式 return 结尾不再误报
- PopulateSha1MapStore 源码末句是 return(vast 解析 body[-1]=Return),但翻译后未 terminated(HandlesReturn L133 HandleExprLlvm 返回 None 时静默跳过 ret)被误判为掉出末尾 - 判据从 builder 状态改为源码结构:末句是 Return 或控制流(If/Match/While/For/Try/With)即不报错;只有末句是普通语句且非 void 注解才 fail-fast - 静态检查(源码)与动态状态(builder block)分离,翻译层问题不该归类为源码掉出缺陷 - NegativeTest missing_return(末句 Assign)仍报错
This commit is contained in:
1 parent
09d03f4525
commit
4b0482657b
1 file changed
+12
-9
@@ -1839,16 +1839,19 @@ class FunctionHandle(BaseHandle):
|
||||
return
|
||||
# fail-fast:有非 void 返回类型注解但函数体掉出末尾(无显式 return 覆盖)
|
||||
# → 立即报错,不静默 ret 0(用户隐式返回规则)。
|
||||
# -> None / -> t.CVoid 视为 Void(掉出 ret void 合法);无注解 → C 风格
|
||||
# 过程(ConstZero,保持现状);其余注解(int/str/...)掉出末尾报错。
|
||||
# 例外:末句是控制流(If/Match/While/For/Try/With)→ 掉出末尾合法
|
||||
# (隐式返回规则:末句控制流 → unreachable)。match/if 等翻译后停在
|
||||
# 合成 after 块(未 terminated)是机械产物,所有 arm 已 terminated 属
|
||||
# 正常(如 fatal_error + return None 样板),不能误判为普通语句掉出。
|
||||
# 判据按**源码层面**函数体末句判断(不依赖 builder 状态——翻译后未
|
||||
# terminated 可能由其它翻译问题导致,如 HandleExprLlvm 返回 None 静默
|
||||
# 跳过 ret,不该归类为"掉出末尾"缺陷):
|
||||
# - 末句是显式 return → 有覆盖,正常
|
||||
# - 末句是控制流(If/Match/While/For/Try/With)→ 掉出合法(隐式返回
|
||||
# 规则:末句控制流 → unreachable;match/if 合成 after 块机械掉出,
|
||||
# 所有 arm 已 terminated 属正常)
|
||||
# - 末句是普通语句 → 真掉出末尾;-> None / -> t.CVoid 视为 Void 合法,
|
||||
# 无注解 → C 风格过程(ConstZero,保持现状);其余注解报错
|
||||
_last_stmt = Node.body[-1] if Node.body else None
|
||||
_is_ctrl_tail: bool = isinstance(_last_stmt, (
|
||||
ast.If, ast.Match, ast.While, ast.For, ast.Try, ast.With))
|
||||
if Node.returns is not None and not _is_ctrl_tail:
|
||||
_is_ret_or_ctrl_tail: bool = isinstance(_last_stmt, (
|
||||
ast.Return, ast.If, ast.Match, ast.While, ast.For, ast.Try, ast.With))
|
||||
if Node.returns is not None and not _is_ret_or_ctrl_tail:
|
||||
_ret_annot_void: bool = (
|
||||
isinstance(Node.returns, ast.Constant) and Node.returns.value is None) or (
|
||||
isinstance(Node.returns, ast.Attribute) and getattr(Node.returns, 'attr', '') == 'CVoid')
|
||||
|
||||
Reference in new issue
Block a user