fixed return bug

This commit is contained in:
pca006132 2020-12-22 15:20:42 +08:00 committed by pca006132
parent 69cf20cb91
commit c99995adc6

View File

@ -133,12 +133,13 @@ def parse_for_stmt(ctx: Context,
if key in used_sym_table: if key in used_sym_table:
if value != used_sym_table[key]: if value != used_sym_table[key]:
raise CustomError('inconsistent type') raise CustomError('inconsistent type')
a, b, r = parse_stmts(ctx, sym_table | binding, used_sym_table | binding, # more sophisticated return analysis is needed...
a, b, _ = parse_stmts(ctx, sym_table | binding, used_sym_table | binding,
return_ty, node.body) return_ty, node.body)
a1, b1, r1 = parse_stmts(ctx, sym_table, used_sym_table | b, a1, b1, _ = parse_stmts(ctx, sym_table, used_sym_table | b,
return_ty, node.orelse) return_ty, node.orelse)
defined = {k: a[k] for k in a if k in a1} defined = {k: a[k] for k in a if k in a1}
return defined, b | b1, r and r1 return defined, b | b1, False
def parse_while_stmt(ctx: Context, def parse_while_stmt(ctx: Context,
sym_table: dict[str, Type], sym_table: dict[str, Type],
@ -149,11 +150,11 @@ def parse_while_stmt(ctx: Context,
if ty != ctx.types['bool']: if ty != ctx.types['bool']:
raise CustomError('condition must be bool') raise CustomError('condition must be bool')
# more sophisticated return analysis is needed... # more sophisticated return analysis is needed...
a, b, r = parse_stmts(ctx, sym_table, used_sym_table, return_ty, node.body) a, b, _ = parse_stmts(ctx, sym_table, used_sym_table, return_ty, node.body)
a1, b1, r1 = parse_stmts(ctx, sym_table, used_sym_table | b, a1, b1, _ = parse_stmts(ctx, sym_table, used_sym_table | b,
return_ty, node.orelse) return_ty, node.orelse)
defined = {k: a[k] for k in a if k in a1} defined = {k: a[k] for k in a if k in a1}
return defined, b | b1, r and r1 return defined, b | b1, False
def parse_return_stmt(ctx: Context, def parse_return_stmt(ctx: Context,
sym_table: dict[str, Type], sym_table: dict[str, Type],