nac3-spec/toy-impl/examples/a.py

66 lines
1.1 KiB
Python

T = TypeVar('T')
class Foo:
a: list[int32]
b: list[int32]
def choose(t: bool, a: T, b: T) -> T:
if t:
return a
else:
return b
def set_list(ls: list[T], a: T):
# this should fail
l2 = ls
l2[-1] = a
def get_foo(a: Foo) -> list[int32]:
return a.a
def set_foo(a: Foo, b: Foo):
a.a[0] = b.a[0]
if True:
c = b
# this should fail
c.a = a.a
def set_foo2(a: Foo, b: Foo):
a.a[0] = b.a[0]
if True:
c = [Foo()]
c[0] = a
# this should fail
c[0].a = b.a
def set_foo3(a: Foo, b: Foo):
a.a[0] = b.a[0]
if True:
c = [Foo()]
c[0] = a
# this should fail
c[0].a = get_foo(b)
def set_foo4(a: Foo, b: Foo):
a.a[0] = b.a[0]
if True:
c = [Foo()]
d = c
d[0] = a
# this should fail
c[0].a = get_foo(b)
def set_foo5(a: Foo, b: Foo):
a.a[0] = b.a[0]
if True:
c = [Foo()]
d = c
e = d
f = e
f[0] = a
# this should fail
c[0].a = get_foo(b)