Files
TransPyC/Test/NoVTableCrossMixinTest/App/main.vp
T
TermiNexus bd5d2467ab fix(exprcall): NoVTable 跨 Mixin self. 调用按定义类解析 + this 前移
缺陷(TPV bootstrap 的 undefined symbol: <sha1>.StmtGenDeclMixin.translate_return
同根因):NoVTable 多继承下,BaseB.caller 内 self.helper()(helper 定义在兄弟
Mixin BaseA,经 Combined(BaseA, BaseB) 组合)被 mangle 成 BaseB.helper —— 用
调用者类做前缀,而定义符号是 BaseA.helper -> ld.lld undefined symbol。

修复(HandlesExprCall.py):
1. 调用端 MRO 回退失败后,全局扫描已注册类找方法定义类(兄弟 Mixin 兜底);
2. _adjust_this_for_inherited_method 支持"调用类不含定义类字段"场景:
   this 按组合布局前移 sizeof(定义类 struct)(BaseB* -> BaseA*)。

新增 Test/NoVTableCrossMixinTest 回归(caller()==42 通过),TestsOverview 记录。
2026-08-20 10:23:47 +08:00

51 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import t
import stdio
import testcheck
# ============================================================
# 复现:NoVTable 多继承下跨 Mixin self. 方法调用
#
# 缺陷:BaseB.caller 内 `self.helper()`(helper 定义在兄弟 Mixin BaseA,
# 经 Combined 多继承组合)被 mangle 成 `<sha1>.BaseB.helper`
# (用调用者自身/直接父类做前缀),而定义符号是 `<sha1>.BaseA.helper`
# → ld.lld undefined symbol(TPV 侧 StmtGenMixin.translate_stmt 调
# self.translate_return 同根因,符号成 StmtGenDeclMixin.translate_return)。
# 期望:按实际定义类(BaseA)做前缀,或按最终组合类(Combined)。
# ============================================================
@t.NoVTable
class BaseA:
a: t.CInt
def helper(self) -> int:
return self.a
@t.NoVTable
class BaseB:
b: t.CInt
def caller(self) -> int:
return self.helper()
@t.NoVTable
class Combined(BaseA, BaseB):
pass
def test_cross_mixin_call():
testcheck.section("Test 1: cross-mixin self. call")
c: Combined = Combined()
c.a = 42
c.b = 7
testcheck.check(c.caller() == 42,
"caller()==42 (BaseB->BaseA)",
"cross-mixin call fail")
def main() -> t.CInt:
testcheck.begin("NoVTableCrossMixinTest")
test_cross_mixin_call()
return testcheck.end()