-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
If a variable is annotated with a tuple type, Retic does not dynamically check the contents of the tuple at dereferences.
A program:
def f(x:(Int,Int))->String:
return x[0] + x[1]
retic -p
def f(x):
check_type_tuple(x, 2)
return check_type_string((x[0] + x[1]))
f = check_type_function(f)
Sure tuples are immutable, but:
- an untyped context could supply a tuple containing bad values to a typed function (Example 1)
- tuples can contain mutable values (Example 2)
Example 1
def f(x:(Int,Int))->String:
return x[0] + x[1] # Not sure why this type checks
def main(x)->String:
return f(x)
main(("A", "B"))
Example 2
def g(x:(List(Int),Int))->(List(Int), Int):
x[0][0] = "yolo"
return x
print(g(([0], 0)))
# (["yolo", 0])
Metadata
Metadata
Assignees
Labels
No labels