fix(method): list 特化缺方法时回退裸模板

list[AST*].get 等特化方法未生成时,回退调用 list.get,避免 Undefined method。
This commit is contained in:
TermiNexus committed 2026-10-18 17:32:44 +08:00
1 parent 0f1a2e9fbb
commit a410de2cf7
1 file changed
+16
+16
View File
@@ -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: