allow type guard on unbounded type variables
This commit is contained in:
parent
07bc512e59
commit
a46edc8a47
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue