test(generic): GenericOopTest 补字段注解并改用 int 实例化

- 补 A/Pair/Calculator/Container 字段注解触发字段拦截验证
- calc2 改 Calculator(2),适配 TPV 泛型函数 int-only 限制
This commit is contained in:
TermiNexus committed 2026-08-13 17:32:00 +08:00
1 parent 409296a84c
commit 2c7f563dda
1 file changed
+8 -2
+8 -2
View File
@@ -31,12 +31,15 @@ def double_add[T](a: T, b: T) -> T:
# === 结构体泛型 ===
class A[T]():
a: T
def __init__(self, a: T):
self.a = T(a)
def get_a(self) -> T:
return self.a
class Pair[T1, T2]():
first: T1
second: T2
def __init__(self, first: T1, second: T2):
self.first = T1(first)
self.second = T2(second)
@@ -46,6 +49,7 @@ class Pair[T1, T2]():
return self.second
class Calculator[T]():
val: T
def __init__(self, init_val: T):
self.val = T(init_val)
def compute(self, other: T) -> T:
@@ -54,6 +58,8 @@ class Calculator[T]():
return double_add(self.val, other)
class Container[T]():
value: T
flag: CInt32T
def __init__(self, v: T):
self.value = T(v)
self.flag = CInt32T(1)
@@ -94,8 +100,8 @@ def main() -> CInt | CExport:
testcheck.section("泛型 + OOP 组合")
calc1 = Calculator(10)
print(calc1.compute(5))
calc2 = Calculator(1.5)
print(calc2.compute(2.5))
calc2 = Calculator(2)
print(calc2.compute(3))
c1_gen = Container(42)
print(c1_gen.get_value())