From 3cdb5eefe486e156220de8ffd6ee7c3e746ed1a6 Mon Sep 17 00:00:00 2001 From: Hans Delano Date: Tue, 10 Sep 2024 00:28:12 +0800 Subject: [PATCH] fix: second statement is a return statement in a block statement --- .../__tests__/__snapshots__/stepper.ts.snap | 888 ++++++++++++++++++ src/stepper/stepper.ts | 5 +- 2 files changed, 891 insertions(+), 2 deletions(-) diff --git a/src/stepper/__tests__/__snapshots__/stepper.ts.snap b/src/stepper/__tests__/__snapshots__/stepper.ts.snap index fee15d2af..7db6a5dd5 100644 --- a/src/stepper/__tests__/__snapshots__/stepper.ts.snap +++ b/src/stepper/__tests__/__snapshots__/stepper.ts.snap @@ -6320,6 +6320,894 @@ expmod(4, 3, 5); } } }; + +{ + { + { + return 4 * expmod(4, 3 - 1, 5) % 5; + } + } +}; + +{ + { + { + return 4 * expmod(4, 3 - 1, 5) % 5; + } + } +}; + +{ + { + return 4 * expmod(4, 3 - 1, 5) % 5; + } +}; + +{ + { + return 4 * expmod(4, 3 - 1, 5) % 5; + } +}; + +{ + return 4 * expmod(4, 3 - 1, 5) % 5; +}; + +{ + return 4 * expmod(4, 3 - 1, 5) % 5; +}; + +4 * expmod(4, 3 - 1, 5) % 5; + +4 * expmod(4, 3 - 1, 5) % 5; + +4 * expmod(4, 2, 5) % 5; + +4 * expmod(4, 2, 5) % 5; + +4 * { + if (2 === 0) { + return 1; + } else { + if (is_even(2)) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + if (2 === 0) { + return 1; + } else { + if (is_even(2)) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + if (false) { + return 1; + } else { + if (is_even(2)) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + if (false) { + return 1; + } else { + if (is_even(2)) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + { + if (is_even(2)) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + { + if (is_even(2)) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + { + if (2 % 2 === 0) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + { + if (2 % 2 === 0) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + { + if (0 === 0) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + { + if (0 === 0) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + { + if (true) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + { + if (true) { + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 2 - 1, 5) % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = expmod(4, 2 / 2, 5); + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = expmod(4, 1, 5); + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = expmod(4, 1, 5); + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + if (1 === 0) { + return 1; + } else { + if (is_even(1)) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + if (1 === 0) { + return 1; + } else { + if (is_even(1)) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + if (false) { + return 1; + } else { + if (is_even(1)) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + if (false) { + return 1; + } else { + if (is_even(1)) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + if (is_even(1)) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + if (is_even(1)) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + if (1 % 2 === 0) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + if (1 % 2 === 0) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + if (1 === 0) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + if (1 === 0) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + if (false) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + if (false) { + const to_half = expmod(4, 1 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + { + undefined; + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + { + undefined; + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + { + return 4 * expmod(4, 1 - 1, 5) % 5; + } + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + return 4 * expmod(4, 1 - 1, 5) % 5; + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = { + return 4 * expmod(4, 1 - 1, 5) % 5; + }; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * expmod(4, 1 - 1, 5) % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * expmod(4, 1 - 1, 5) % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * expmod(4, 0, 5) % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * expmod(4, 0, 5) % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * { + if (0 === 0) { + return 1; + } else { + if (is_even(0)) { + const to_half = expmod(4, 0 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 0 - 1, 5) % 5; + } + } + } % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * { + if (0 === 0) { + return 1; + } else { + if (is_even(0)) { + const to_half = expmod(4, 0 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 0 - 1, 5) % 5; + } + } + } % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * { + if (true) { + return 1; + } else { + if (is_even(0)) { + const to_half = expmod(4, 0 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 0 - 1, 5) % 5; + } + } + } % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * { + if (true) { + return 1; + } else { + if (is_even(0)) { + const to_half = expmod(4, 0 / 2, 5); + return to_half * to_half % 5; + } else { + return 4 * expmod(4, 0 - 1, 5) % 5; + } + } + } % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * { + { + return 1; + } + } % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * { + { + return 1; + } + } % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * { + return 1; + } % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * { + return 1; + } % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * 1 % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 * 1 % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4 % 5; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + const to_half = 4; + return to_half * to_half % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + return 4 * 4 % 5; + } + } +} % 5; + +4 * { + { + { + undefined; + return 4 * 4 % 5; + } + } +} % 5; + +4 * { + { + { + return 4 * 4 % 5; + } + } +} % 5; + +4 * { + { + { + return 4 * 4 % 5; + } + } +} % 5; + +4 * { + { + return 4 * 4 % 5; + } +} % 5; + +4 * { + { + return 4 * 4 % 5; + } +} % 5; + +4 * { + return 4 * 4 % 5; +} % 5; + +4 * { + return 4 * 4 % 5; +} % 5; + +4 * (4 * 4 % 5) % 5; + +4 * (4 * 4 % 5) % 5; + +4 * (16 % 5) % 5; + +4 * (16 % 5) % 5; + +4 * 1 % 5; + +4 * 1 % 5; + +4 % 5; + +4 % 5; + +4; + +4; " `; diff --git a/src/stepper/stepper.ts b/src/stepper/stepper.ts index 23be27b58..b4471c308 100644 --- a/src/stepper/stepper.ts +++ b/src/stepper/stepper.ts @@ -2032,8 +2032,9 @@ function reduceMain( const stmt = ast.expressionStatement(firstStatement.expression) return [stmt, context, paths, explain(node)] } else if ( - secondStatement.type == 'ExpressionStatement' && - isIrreducible(secondStatement.expression, context) + (secondStatement.type == 'ExpressionStatement' && + isIrreducible(secondStatement.expression, context)) || + secondStatement.type == 'ReturnStatement' ) { paths[0].push('body[0]') paths.push([])