allow type guard on unbounded type variables

This commit is contained in:
pca006132 2020-12-23 17:08:04 +08:00 committed by pca006132
parent 07bc512e59
commit a46edc8a47
1 changed files with 3 additions and 3 deletions

View File

@ -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)