From 00c385dc94ebde4b140bda151874da82695998fe Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 24 Oct 2026 16:19:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(overload):=20=E7=AD=BE=E5=90=8D=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E6=94=B9=E7=94=A8=E7=B1=BB=E5=86=85=20=5Foverload=5Fa?= =?UTF-8?q?ppend=EF=BC=8C=E9=81=BF=E5=85=8D=E8=B7=A8=20mixin=20=E8=B0=83?= =?UTF-8?q?=E7=94=A8=20FuncGenBase.=5Fappend=5Fstr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FuncGenDef 与 FuncGenBase 是兄弟 mixin,MRO 中不含对方;在 FuncGenDef 里调用 self._append_str 会让调用点解析失败(method return type cannot be obtained precisely: _append_str)。改为 FuncGenDef 自己的有界追加,并把超长判定并进去重处理。 --- App/lib/core/Gen/Func/FuncGenDef.vp | 31 +++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/App/lib/core/Gen/Func/FuncGenDef.vp b/App/lib/core/Gen/Func/FuncGenDef.vp index e2dd135..6faaab5 100644 --- a/App/lib/core/Gen/Func/FuncGenDef.vp +++ b/App/lib/core/Gen/Func/FuncGenDef.vp @@ -86,6 +86,18 @@ novirtual class FuncGenDef(CallGenBase.CallGenBase): if self.Gen.CallGenLeafKit.count_owned_overloads(trans._funcs, trans._func_count, name, trans.ModuleSha1) >= 2: return 1 return 0 + # _overload_append - 有界追加(本类局部工具)。 + # 不能调用 FuncGenBase._append_str:FuncGenDef 与 FuncGenBase 是同一层的兄弟 mixin, + # FuncGenDef 的 MRO 里没有 FuncGenBase(编译期会报 "method return type cannot be obtained")。 + def _overload_append(self, buf: str, s: str) -> int: + """把 s 追加到 buf(上限 OVERLOAD_SIG_TEXT_MAX);0=成功 / 1=超长""" + if buf is None or s is None: return 1 + cur: sizet = string.strlen(buf) + ln: sizet = string.strlen(s) + if cur + ln + 1 > OVERLOAD_SIG_TEXT_MAX: return 1 + string.strcpy(buf + cur, s) + return 0 + # _overload_sig_text - 重载签名文本:把每个形参的类型写成 SpecToText 规范文本后逗号连接。 # 用注解(而不是 LLVM 类型)生成:LLVM 没有符号性,int/uint 会撞;走 SpecFromLLVMType + # SpecWithSign 后别名展开为 i32/u32,指针是 p:i32,结构体是 st:{模块sha1}.类名 @@ -148,23 +160,30 @@ novirtual class FuncGenDef(CallGenBase.CallGenBase): self.Gen.TypeGenErr.fatal_error(arg, f"overloaded function '{fd.name}' parameter '{arg.arg}' signature text too long", "InternalCompilerError") return None if first == 0: - if string.strlen(buf) + 2 > OVERLOAD_SIG_TEXT_MAX: + if self._overload_append(buf, ",") != 0: stdlib.free(buf) stdlib.free(one) self.Gen.TypeGenErr.fatal_error(fd, f"overloaded function '{fd.name}' parameter list is too long", "InternalCompilerError") return None - self._append_str(buf, ",", OVERLOAD_SIG_TEXT_MAX) first = 0 - if string.strlen(buf) + string.strlen(one) + 2 > OVERLOAD_SIG_TEXT_MAX: + if self._overload_append(buf, one) != 0: stdlib.free(buf) stdlib.free(one) self.Gen.TypeGenErr.fatal_error(fd, f"overloaded function '{fd.name}' parameter list is too long", "InternalCompilerError") return None - self._append_str(buf, one, OVERLOAD_SIG_TEXT_MAX) # *args -> 可变参数标记,必须与定参区分开(ORFunc(int) 与 ORFunc(int, ...) 是两个重载) if ags.vararg is not None: - if first == 0: self._append_str(buf, ",", OVERLOAD_SIG_TEXT_MAX) - self._append_str(buf, "...", OVERLOAD_SIG_TEXT_MAX) + if first == 0: + if self._overload_append(buf, ",") != 0: + stdlib.free(buf) + stdlib.free(one) + self.Gen.TypeGenErr.fatal_error(fd, f"overloaded function '{fd.name}' parameter list is too long", "InternalCompilerError") + return None + if self._overload_append(buf, "...") != 0: + stdlib.free(buf) + stdlib.free(one) + self.Gen.TypeGenErr.fatal_error(fd, f"overloaded function '{fd.name}' parameter list is too long", "InternalCompilerError") + return None first = 0 stdlib.free(one) return buf