2022-03-18 16:52:52 +08:00
|
|
|
@extern
|
|
|
|
def output_int32(x: int32):
|
|
|
|
...
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def foo(self):
|
|
|
|
output_int32(1)
|
|
|
|
|
|
|
|
class B:
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def foo(self):
|
|
|
|
output_int32(2)
|
|
|
|
|
|
|
|
|
|
|
|
T = TypeVar("T", A, B)
|
|
|
|
|
|
|
|
|
|
|
|
class C(Generic[T]):
|
|
|
|
x: T
|
|
|
|
|
|
|
|
def __init__(self, x: T):
|
|
|
|
self.x = x
|
|
|
|
|
|
|
|
def foo(self):
|
|
|
|
self.x.foo()
|
|
|
|
|
|
|
|
|
|
|
|
def run() -> int32:
|
|
|
|
insta = A()
|
|
|
|
inst = C(insta)
|
|
|
|
inst.foo()
|
2022-06-01 04:27:18 +08:00
|
|
|
|
|
|
|
insta2 = B()
|
|
|
|
inst2 = C(insta2)
|
|
|
|
inst2.foo()
|
2022-03-18 16:52:52 +08:00
|
|
|
return 0
|
|
|
|
|