diag(viperc): 放宽报错位置兜底判据 + 临时打印定位决策输入(定位后删除)

兜底判据改为:只要实参位置有效,且节点行号“不深于”栈最内层帧行号(或栈为空),就用实参
位置 —— 覆盖 FunctionDef 节点被传下来的情形(其行号恰好等于函数定义行、并非真实表达式)。
另加一行 [TEMP-DIAG](node/curarg/trace/top/shown),用于一次看清兜底为何未触发;
定位完成后立即删除该行。
This commit is contained in:
TermiNexus committed 2026-10-14 17:08:59 +08:00
1 parent 40ea5d6513
commit ca81c1185c
1 file changed
+17 -8
+17 -8
View File
@@ -47,18 +47,19 @@ novirtual class TypeGenErr(TypeGenBase.TypeGenBase):
# 当前帧(错误点)位置:优先 node,其次调用栈最内层有行号的帧,最后 current_file。
lineno: int = 0
if node is not None: lineno = node.lineno
raw_line: int = lineno # [TEMP-DIAG] 兜底前的原始节点行号(定位完删除)
file_name: str = self.Gen.TypeGenResolve.get_current_file()
if file_name is None: file_name = "<unknown>"
# 报错位置兜底顺序(“节点位置不可信”时):
# ① 正在翻译的实参位置(精确到 `&_on_submit` 这类表达式,见 TypeGenBase.set_cur_arg);
# ② 调用栈最内层有行号的帧(给出被调函数的定义位置)。
# “节点位置不可信”的两种情形:lineno==0(合成节点);或节点行号恰好等于当前函数定义行
#(节点其实是 FunctionDef 本身,例如构造器内联路径把它传了下来)。
node_at_func_def: int = 0
# 报错位置兜底(“节点位置不可信”时优先用正在翻译的实参位置,精确定位到
# `&_on_submit` 这类表达式;见 TypeGenBase.set_cur_arg)。判据取宽:节点无行号、
# 或**没有更深的可用位置**(节点行号不深于栈最内层帧的行号 —— 函数体里的真实
# 表达式行号必然大于函数定义行,而 FunctionDef 自身恰好等于定义行/更浅),
# 或栈为空(顶层函数体翻译时可能没有帧)时,都采用实参位置。
deeper_known: int = 0
if lineno > 0 and self.Gen.TypeGenBase.TraceCount > 0:
tfc: GenTypes.TraceFrame* = self.Gen.TypeGenBase._get_trace_frame(self.Gen.TypeGenBase.TraceCount - 1)
if tfc is not None and tfc.lineno > 0 and lineno == tfc.lineno: node_at_func_def = 1
if (lineno <= 0 or node_at_func_def != 0) and self.Gen.TypeGenBase.CurArgLine > 0:
if tfc is not None and tfc.lineno > 0 and lineno > tfc.lineno: deeper_known = 1
if (lineno <= 0 or deeper_known == 0) and self.Gen.TypeGenBase.CurArgLine > 0:
if self.Gen.TypeGenBase.CurArgFile is not None:
file_name = self.Gen.TypeGenBase.CurArgFile
lineno = self.Gen.TypeGenBase.CurArgLine
@@ -84,6 +85,14 @@ novirtual class TypeGenErr(TypeGenBase.TypeGenBase):
Diag.finish()
return 0
# [TEMP-DIAG] 定位“报错位置”问题用(定位完删除):把决策输入打出来
# node=节点原始行号(0=合成) curarg=当前实参行号 trace=栈深 top=栈最内层行号
ti_top: int = -1
if self.Gen.TypeGenBase.TraceCount > 0:
tf_d: GenTypes.TraceFrame* = self.Gen.TypeGenBase._get_trace_frame(self.Gen.TypeGenBase.TraceCount - 1)
if tf_d is not None: ti_top = tf_d.lineno
stdio.printf("[TEMP-DIAG] node=%d curarg=%d trace=%d top=%d -> shown=%d\n",
raw_line, self.Gen.TypeGenBase.CurArgLine, self.Gen.TypeGenBase.TraceCount, ti_top, lineno)
Diag.begin(ent, err_type, msg)
# 调用链帧(按"自外向内"顺序)**由本类遍历**(只有它拿得到 TraceFrame),填入 entry。
for i in range(int(self.Gen.TypeGenBase.TraceCount)):