From ca81c1185c9aadaca38115f8c494252a7a174441 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Wed, 14 Oct 2026 17:08:59 +0800 Subject: [PATCH] =?UTF-8?q?diag(viperc):=20=E6=94=BE=E5=AE=BD=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E4=BD=8D=E7=BD=AE=E5=85=9C=E5=BA=95=E5=88=A4=E6=8D=AE?= =?UTF-8?q?=20+=20=E4=B8=B4=E6=97=B6=E6=89=93=E5=8D=B0=E5=AE=9A=E4=BD=8D?= =?UTF-8?q?=E5=86=B3=E7=AD=96=E8=BE=93=E5=85=A5=EF=BC=88=E5=AE=9A=E4=BD=8D?= =?UTF-8?q?=E5=90=8E=E5=88=A0=E9=99=A4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 兜底判据改为:只要实参位置有效,且节点行号“不深于”栈最内层帧行号(或栈为空),就用实参 位置 —— 覆盖 FunctionDef 节点被传下来的情形(其行号恰好等于函数定义行、并非真实表达式)。 另加一行 [TEMP-DIAG](node/curarg/trace/top/shown),用于一次看清兜底为何未触发; 定位完成后立即删除该行。 --- App/lib/core/Gen/Type/TypeGenErr.vp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/App/lib/core/Gen/Type/TypeGenErr.vp b/App/lib/core/Gen/Type/TypeGenErr.vp index b7066ab..27dc554 100644 --- a/App/lib/core/Gen/Type/TypeGenErr.vp +++ b/App/lib/core/Gen/Type/TypeGenErr.vp @@ -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 = "" - # 报错位置兜底顺序(“节点位置不可信”时): - # ① 正在翻译的实参位置(精确到 `&_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)):