From a46edc8a471202eda70e3fa680a3a8750c0ed7ce Mon Sep 17 00:00:00 2001 From: pca006132 Date: Wed, 23 Dec 2020 17:08:04 +0800 Subject: [PATCH] allow type guard on unbounded type variables --- toy-impl/parse_stmt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/toy-impl/parse_stmt.py b/toy-impl/parse_stmt.py index 864b21a..82f1222 100644 --- a/toy-impl/parse_stmt.py +++ b/toy-impl/parse_stmt.py @@ -126,12 +126,12 @@ def parse_if_stmt(ctx: Context, (isinstance(node.test.ops[0], ast.Eq) or\ isinstance(node.test.ops[0], ast.NotEq)): t = parse_expr(ctx, sym_table, node.test.left.args[0]) - if not isinstance(t, TypeVariable) or len(t.constraints) < 2: + if not isinstance(t, TypeVariable): raise CustomError( - 'type guard only support basic bounded type variables', + 'type guard only support type variables', node.test) t1, _ = parse_type(ctx, node.test.comparators[0]) - if t1 not in t.constraints: + if len(t.constraints) > 0 and t1 not in t.constraints: raise CustomError( f'{t1} is not a possible instance of {t}', node.test)