diff --git a/App/lib/core/Gen/Stmt/StmtGenMixin.vp b/App/lib/core/Gen/Stmt/StmtGenMixin.vp index 127448d..ae14c5d 100644 --- a/App/lib/core/Gen/Stmt/StmtGenMixin.vp +++ b/App/lib/core/Gen/Stmt/StmtGenMixin.vp @@ -32,11 +32,11 @@ novirtual class StmtGenMixin(StmtGenDeclMixin.StmtGenDeclMixin): # define). Every instruction then carries ", !dbg !N". if node is not None and trans._cur_builder is not None: DebugInfoGen.SetStatement(trans.Pool, trans._cur_builder, node.lineno, node.col_offset + 1) - # 让最内层栈帧跟踪“当前语句”位置:报错时栈帧给出的是调用点所在语句,而非函数定义行 - #(Python traceback 口径;配合 TypeGenBase.set_cur_arg 可得到“调用点 + 具体表达式”两帧)。 + # 注意:**不要**用当前语句位置覆盖栈帧(那会把“函数定义帧”与错误帧叠成同一位置、 + # 被去重合并,反而丢掉 `_start` 那帧)。栈帧保留“被调函数的定义位置”, + # “当前语句/具体表达式”由错误帧给出(见 TypeGenErr 的 CurArg 兜底)。 + # 仅在语句边界清掉上一条语句遗留的实参位置,避免兜底定位串味。 if node is not None: - self.Gen.TypeGenBase.update_top_trace_position(node.lineno, node.col_offset + 1) - # 语句边界处清掉上一条语句遗留的实参位置,避免兜底定位“串味”到旧实参 self.Gen.TypeGenBase.set_cur_arg(None, 0, 0) if trans.TranslateDepth >= HT.TRANSLATE_MAX_DEPTH: self.Gen.TypeGenErr.fatal_error(node, "statement translation nested too deeply (likely an AST self-reference cycle or a translation bug)", "RecursionError") trans.TranslateDepth += 1 diff --git a/App/lib/core/Gen/Type/TypeGenBase.vp b/App/lib/core/Gen/Type/TypeGenBase.vp index ab06724..c048ddd 100644 --- a/App/lib/core/Gen/Type/TypeGenBase.vp +++ b/App/lib/core/Gen/Type/TypeGenBase.vp @@ -207,16 +207,6 @@ novirtual class TypeGenBase: frame.lineno = 0 frame.col_start = 0 frame.col_end = 0 - # update_top_trace_position - 让最内层栈帧跟踪“当前语句”位置(Python traceback 口径: - # 帧行号随语句推进而更新)。这样报错时栈帧给出的是**调用点所在语句**,而不是函数定义行; - # 配合 set_cur_arg,即可得到“调用点 + 具体表达式”两帧。 - def update_top_trace_position(self, lineno: int, col_start: int) -> None: - """Track the current statement on the innermost trace frame.""" - if self.TraceCount <= 0 or lineno <= 0: return - frame: GenTypes.TraceFrame* = self._get_trace_frame(self.TraceCount - 1) - if frame is None: return - frame.lineno = lineno - frame.col_start = col_start # set_cur_arg - 记录正在翻译的实参位置(file/line/col),供“合成节点无行号”时兜底定位。 def set_cur_arg(self, file_name: str, lineno: int, col_start: int) -> None: """Remember the argument position currently being translated."""