Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tuple contents are not dynamically checked #36

Open
bennn opened this issue May 15, 2017 · 0 comments
Open

tuple contents are not dynamically checked #36

bennn opened this issue May 15, 2017 · 0 comments

Comments

@bennn
Copy link

bennn commented May 15, 2017

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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant