diff --git a/App/lib/core/Gen/Call/CallGenCall.vp b/App/lib/core/Gen/Call/CallGenCall.vp index d468148..e621d63 100644 --- a/App/lib/core/Gen/Call/CallGenCall.vp +++ b/App/lib/core/Gen/Call/CallGenCall.vp @@ -385,6 +385,22 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): self.Gen.TypeGenErr.fatal_error(node, err_cm4) self.Gen.TypeGenErr.fatal_error(node, "方法返回类型无法确定") + # __new__ 的签名可能**短于** __init__:ctor 路径把 ctor 实参**全量**转发给 + # __new__,会多传尾参 ⇒ call 实参数 > declare 形参数 + # (mlir-opt: "llvm.call op incorrect number of operands (8) for callee + # (expecting: 7)";现场 ast.FunctionDef.__new__ 无 type_params,而 + # __init__ 有 `type_params = None`,调用点仍按 ctor 全量传 7 个)。 + # 按被调方(declare/vpi 解析出的)非-self 形参数**截掉尾参**:这些尾参 + # __new__ 本就不接收,语义上由 __init__ 消费(__new__ 只负责分配存储)。 + if string.strcmp(method_name, "__new__") == 0 and found_func is not None: + nn_pc: int = 0 + nn_pn: mlirlite.Param* = mlirlite.function_get_param_head(found_func) + while nn_pn is not None: + nn_pc += 1 + nn_pn = mlirlite.param_get_next(nn_pn) + if nn_pc > 1 and extra_count > nn_pc - 1: + extra_count = nn_pc - 1 + # 构建参数链表: self_ptr → extra_args... mlirlite.value_set_next(self_ptr, None) head: mlirlite.Value* = self_ptr