From a410de2cf7fffbbb514c5b060f0b4fbabef091c4 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sun, 18 Oct 2026 17:32:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(method):=20list=20=E7=89=B9=E5=8C=96?= =?UTF-8?q?=E7=BC=BA=E6=96=B9=E6=B3=95=E6=97=B6=E5=9B=9E=E9=80=80=E8=A3=B8?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit list[AST*].get 等特化方法未生成时,回退调用 list.get,避免 Undefined method。 --- lib/core/Handles/HandlesExprCall.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/core/Handles/HandlesExprCall.py b/lib/core/Handles/HandlesExprCall.py index 35e5022..892ff57 100644 --- a/lib/core/Handles/HandlesExprCall.py +++ b/lib/core/Handles/HandlesExprCall.py @@ -3921,6 +3921,22 @@ class ExprCallHandle(BaseHandle): adjusted = Gen._adjust_args(call_args_fb, func) result = Gen.builder.call(func, adjusted, name=f"call_{FullMethodName}") return result + if ClassName.startswith('list[') and ClassName in Gen.structs: + # 泛型特化方法未生成时,回退到裸模板 list 的同名方法 + struct_type = Gen.structs[ClassName] + self_ptr_type = ir.PointerType(struct_type) + BareFuncName: str = f'list.{MethodName}' + func = Gen._find_function(BareFuncName) + if func is not None: + if isinstance(ObjVal.type, ir.PointerType) and ObjVal.type.pointee == struct_type: + call_self = ObjVal + else: + call_self = Gen.builder.bitcast(ObjVal, self_ptr_type, name=f"method_self_{ClassName}") + call_args_fb = [call_self] + CallArgs + self._fill_default_args(call_args_fb, func, BareFuncName) + self._append_eh_msg_out_arg(call_args_fb, func, Gen) + adjusted = Gen._adjust_args(call_args_fb, func) + return Gen.builder.call(func, adjusted, name=f"call_{BareFuncName}") raise Exception(f"Undefined method '{MethodName}' in class '{ClassName}' (no function declaration found for '{FullMethodName}')") def _EnsureReceiverStructConcrete(self, ClassName: str, class_sha1: str | None, ObjVal: Any, Gen: "LlvmGeneratorMixin") -> Any: