From 20d87db9d5fcdb9fc2cf19900616f93fa012ad24 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sun, 15 Jul 2018 13:57:11 -0700 Subject: [PATCH] Fix up stacks for type checking. Sometimes (e.g. 'clear') the () at the end of the stack was tripping up the unify() function. --- joy/utils/polytypes.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/joy/utils/polytypes.py b/joy/utils/polytypes.py index 45d2e73..acba4b8 100644 --- a/joy/utils/polytypes.py +++ b/joy/utils/polytypes.py @@ -355,6 +355,8 @@ def type_check(name, stack): except KeyError: return # None, indicating unknown + stack = _foo_stack(stack) + for fi, fo in infer(func): try: U = unify(fi, stack) @@ -369,6 +371,16 @@ def type_check(name, stack): return False +def _foo_stack(stack, s=None): + if s is None: + s = (StackJoyType(n) for n in xrange(23, 100)) + if stack == (): + return next(s) + if isinstance(stack, tuple): + return tuple(_foo_stack(inner, s) for inner in stack) + return stack + + a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 = A b0, b1, b2, b3, b4, b5, b6, b7, b8, b9 = B n0, n1, n2, n3, n4, n5, n6, n7, n8, n9 = N