From 7fd8009fcfe07d995adb981c303f2758bb9c4a10 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Thu, 16 Jul 2020 15:27:25 +0300 Subject: [PATCH] fix: break out of for loops prior to returning --- vyper/codegen/return_.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/vyper/codegen/return_.py b/vyper/codegen/return_.py index 93d8941b64..dc1bc9f98b 100644 --- a/vyper/codegen/return_.py +++ b/vyper/codegen/return_.py @@ -26,12 +26,6 @@ def make_return_stmt(stmt, context, begin_pos, _size, loop_memory_position=None) if isinstance(begin_pos, int) and isinstance(_size, int): # static values, unroll the mloads instead. mloads = [["mload", pos] for pos in range(begin_pos, _size, 32)] - return ( - ["seq_unchecked"] - + mloads - + nonreentrant_post - + [["jump", ["mload", context.callback_ptr]]] - ) else: mloads = [ "seq_unchecked", @@ -54,12 +48,17 @@ def make_return_stmt(stmt, context, begin_pos, _size, loop_memory_position=None) ["goto", start_label], ["label", exit_label], ] - return ( - ["seq_unchecked"] - + [mloads] - + nonreentrant_post - + [["jump", ["mload", context.callback_ptr]]] - ) + + # if we are in a for loop, we have to exit prior to returning + exit_repeater = ["exit_repeater"] if context.forvars else [] + + return ( + ["seq_unchecked"] + + exit_repeater + + mloads + + nonreentrant_post + + [["jump", ["mload", context.callback_ptr]]] + ) else: return ["seq_unchecked"] + nonreentrant_post + [["return", begin_pos, _size]]