You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
1.6 KiB

# class defs
class A_CLASS(object):
a_class_i:int = 0
def __init__(self:"A_CLASS", x:int):
self.x = x
# Bad, self param is missing
def add(y:int) -> int:
y = y+self.x
return y
class B_CLASS(object):
b_class_i:int = 0
class C_CLASS(B_CLASS):
pass
# Bad, duplicate class def
class A_CLASS(object):
pass
# Bad, E_CLASS is not declared
class D_CLASS(E_CLASS):
pass
# var defs
a_s:str = "a_s"
b_s:str = "b_s"
c_s:str = "c_s"
a_i:int = 0
b_i:int = 0
c_i:int = 0
a_b:bool = False
b_b:bool = False
c_b:bool = False
a_list:[int] = None
b_list:[int] = None
c_list:[int] = None
a_class:A_CLASS = None
b_class:B_CLASS = None
c_class:C_CLASS = None
# fun defs
def f_1() -> object:
def f_f_1() -> object:
# a_s:int = 0 Fails if we uncomment this line
global a_s # Bad, duplicate declarion
print(a_s)
pass
pass
def f_2() -> object:
f_a_s:str = "s"
def f_f_2() -> object:
nonlocal f_a_s
print(f_a_s)
pass
pass
def f_3(x:int) -> bool:
f_b_s:int = 3
if (x + f_b_s > 3):
return True
elif (x + f_b_s == 3):
print("Equal") # Bad, this path should return
return False
def f_4() -> object:
f_a_i:int = 2
a_i = f_a_i + 1 # Bad, cant assign to a_i without declaring it as global or nonlocal
return f_a_i
# NEGATIVE TEST CASES - SEMANTIC
# Bad, f_2 cannot be redefined in the same scope
def f_2() -> object:
pass
# Bad, print cannot be redefined in the same scope
def print(val:object) -> object:
pass
# Bad, a_i cannot be redefined in the same scope
a_i:int = 2
# Bad return
return a_i