diff --git a/App/lib/core/Gen/Expr/ExprGenOps.vp b/App/lib/core/Gen/Expr/ExprGenOps.vp index 4a47bde..d547d42 100644 --- a/App/lib/core/Gen/Expr/ExprGenOps.vp +++ b/App/lib/core/Gen/Expr/ExprGenOps.vp @@ -755,14 +755,6 @@ novirtual class ExprGenOps(ExprGenBase.ExprGenBase): gv_ao: mlirlite.GlobalVariable* = self.Gen.ExprGenAttr.find_global_in_module(mod, nm_ao.id) if gv_ao is not None and gv_ao.Name is not None and gv_ao.Ty is not None: v_ao = self.Gen.ExprGenAttr.make_global_ref(pool, gv_ao.Name, gv_ao.Ty) if v_ao is not None and v_ao.Ty is not None: - # 闭包变量(嵌套 `def f()` 被提升后在父函数里是一个 **i8\*\*** 槽,见 - # FuncGenMixin.translate_nested_function_def 第 13e 步):变量自身就是那个 - # 函数的闭包指针,`&f` 应给出它的**值**(一级 i8*),而不是槽地址 i8**(二级) - # ——否则传给 `callback: t.CPtr` 会因级数不符报 CastError(source level 2 -> - # target level 1)。与“函数名即地址(同 C)”一致。闭包槽与普通函数指针变量 - # 同为 i8**、类型上无法区分,故用闭包名表判定(第 13e 步已登记该名字)。 - if self.Gen.CallGenLeafKit.is_closure_name(nm_ao.id) != 0 and v_ao.Ty.Pointee is not None: - return mlirlite.build_load(builder, v_ao.Ty.Pointee, v_ao) # Object-pointer variable (alloca is Ptr(Ptr(Struct))): the variable is the object, return the object pointer (load once), aligned with translate_c_addr. match v_ao.Ty: case mlirlite.LLVMType.Ptr(ao1): diff --git a/App/lib/core/Gen/Type/TypeGenErr.vp b/App/lib/core/Gen/Type/TypeGenErr.vp index d0aceb2..27dc554 100644 --- a/App/lib/core/Gen/Type/TypeGenErr.vp +++ b/App/lib/core/Gen/Type/TypeGenErr.vp @@ -47,6 +47,7 @@ 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 = "" # 报错位置兜底(“节点位置不可信”时优先用正在翻译的实参位置,精确定位到 @@ -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)):