From 2c7f563ddadcf4d52528e5c491948d4bf6739ac9 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 13 Aug 2026 17:32:00 +0800 Subject: [PATCH] =?UTF-8?q?test(generic):=20GenericOopTest=20=E8=A1=A5?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=B3=A8=E8=A7=A3=E5=B9=B6=E6=94=B9=E7=94=A8?= =?UTF-8?q?=20int=20=E5=AE=9E=E4=BE=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 补 A/Pair/Calculator/Container 字段注解触发字段拦截验证 - calc2 改 Calculator(2),适配 TPV 泛型函数 int-only 限制 --- Test/GenericOopTest/App/main.vp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Test/GenericOopTest/App/main.vp b/Test/GenericOopTest/App/main.vp index 5546144..307b858 100644 --- a/Test/GenericOopTest/App/main.vp +++ b/Test/GenericOopTest/App/main.vp @@ -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())