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)