diff --git a/App/lib/core/Gen/Call/CallGenMixin.vp b/App/lib/core/Gen/Call/CallGenMixin.vp index 9c96631..b2d82dd 100644 --- a/App/lib/core/Gen/Call/CallGenMixin.vp +++ b/App/lib/core/Gen/Call/CallGenMixin.vp @@ -282,6 +282,12 @@ novirtual class CallGenMixin(CallGenBase.CallGenBase): gen_ctor_entry = self.Gen.StructGen.find_struct_by_module(func_name, trans.ModuleSha1) if gen_ctor_entry is None: gen_ctor_entry = self.Gen.StructGen.find_struct(func_name) + # 前向声明占位(裸泛型模板注解 `Class` 无实参时由 TypeGenResolve 登记) + # 不是真实结构体定义:不作为裸名构造的 struct_ty,交由下方泛型推断按实参 + # 特化(与模块限定分支同口径)。 + if gen_ctor_entry is not None and gen_ctor_entry.IsForwardDecl != 0 \ + and self.Gen.ClassGenGeneric._find_generic_template(func_name) is not None: + gen_ctor_entry = None if gen_ctor_entry is not None: struct_ty = gen_ctor_entry.Ty elif trans is not None and cl.func is not None and cl.func.kind() == ast.ASTKind.Attribute: @@ -398,7 +404,16 @@ novirtual class CallGenMixin(CallGenBase.CallGenBase): # 支持模块限定调用(vector.Vector(...)):func_name 是 attr("Vector"), # 需确认模块已导入(模板查找兜底——普通函数如 stdlib.free 的 attr 找 # 不到模板 → 回落普通调用)。 - if struct_ty is None and gen_ctor_entry is None and trans is not None: + # 前向声明占位(注解 `Mod.Class` 未带类型实参时,TypeGenResolve 会登记一个 + # 不透明的 `{sha}.Class` 条目,IsForwardDecl=1)不是真实结构体定义。当该类名 + # 是已注册泛型模板时,占位不得阻断下方泛型推断:否则 `vector.Vector(...)` 会 + # 被静默当普通结构体/函数构造处理,造出裸泛型基类对象,随后方法调用触发 + # D25 接收者 fail-fast(VectorGenericTest 根因)。 + gen_ctor_is_fwd_generic: int = 0 + if gen_ctor_entry is not None and gen_ctor_entry.IsForwardDecl != 0: + if self.Gen.ClassGenGeneric._find_generic_template(func_name) is not None: + gen_ctor_is_fwd_generic = 1 + if struct_ty is None and (gen_ctor_entry is None or gen_ctor_is_fwd_generic != 0) and trans is not None: is_gen_bare: int = 0 if cl.func is not None and cl.func.kind() == ast.ASTKind.Name: is_gen_bare = 1