blob: 422b4668972f8c7a3cac704b6d9c3abd3498bf2c [file] [log] [blame]
[case testGenericFunction]
from typing import TypeVar, List
T = TypeVar('T')
def f(x: T) -> T:
return x
def g(x: List[T]) -> List[T]:
return [x[0]]
def h(x: int, y: List[int]) -> None:
x = f(x)
y = g(y)
[out]
def f(x):
x :: object
L0:
return x
def g(x):
x :: list
r0 :: short_int
r1 :: object
r2 :: list
L0:
r0 = 0
r1 = x[r0] :: list
r2 = [r1]
return r2
def h(x, y):
x :: int
y :: list
r0, r1 :: object
r2 :: int
r3 :: list
r4 :: None
L0:
r0 = box(int, x)
r1 = f(r0)
r2 = unbox(int, r1)
x = r2
r3 = g(y)
y = r3
r4 = None
return r4
[case testGenericAttrAndTypeApplication]
from typing import TypeVar, Generic
T = TypeVar('T')
class C(Generic[T]):
x: T
def f() -> None:
c = C[int]()
c.x = 1
2 + c.x
[out]
def f():
r0, c :: __main__.C
r1 :: short_int
r2 :: object
r3 :: bool
r4 :: short_int
r5 :: object
r6, r7 :: int
r8 :: None
L0:
r0 = C()
c = r0
r1 = 1
r2 = box(short_int, r1)
c.x = r2; r3 = is_error
r4 = 2
r5 = c.x
r6 = unbox(int, r5)
r7 = r4 + r6 :: int
r8 = None
return r8
[case testGenericMethod]
from typing import TypeVar, Generic
T = TypeVar('T')
class C(Generic[T]):
x: T
def __init__(self, x: T) -> None:
self.x = x
def get(self) -> T:
return self.x
def set(self, y: T) -> None:
self.x = y
def f(x: C[int]) -> None:
y = x.get()
x.set(y + 1)
x = C(2)
[out]
def C.__init__(self, x):
self :: __main__.C
x :: object
r0 :: bool
r1 :: None
L0:
self.x = x; r0 = is_error
r1 = None
return r1
def C.get(self):
self :: __main__.C
r0 :: object
L0:
r0 = self.x
return r0
def C.set(self, y):
self :: __main__.C
y :: object
r0 :: bool
r1 :: None
L0:
self.x = y; r0 = is_error
r1 = None
return r1
def f(x):
x :: __main__.C
r0 :: object
r1, y :: int
r2 :: short_int
r3 :: int
r4 :: object
r5 :: None
r6 :: short_int
r7 :: object
r8 :: __main__.C
r9 :: None
L0:
r0 = x.get()
r1 = unbox(int, r0)
y = r1
r2 = 1
r3 = y + r2 :: int
r4 = box(int, r3)
r5 = x.set(r4)
r6 = 2
r7 = box(short_int, r6)
r8 = C(r7)
x = r8
r9 = None
return r9