diff --git a/docs/features/differences.md b/docs/features/differences.md index 746084e8..f7cfa6b3 100644 --- a/docs/features/differences.md +++ b/docs/features/differences.md @@ -37,4 +37,5 @@ The easiest way to test a feature is to [try it on your browser](https://pocketp 6. A `Tab` is equivalent to 4 spaces. You can mix `Tab` and spaces in indentation, but it is not recommended. 7. `%`, `&`, `//`, `^` and `|` for `int` behave the same as C, not python. 8. `str.split` and `str.splitlines` will remove all empty entries. +9. A return, break, continue in try/except block will make the finally block not executed. diff --git a/docs/retype.yml b/docs/retype.yml index 30ca530a..9e700033 100644 --- a/docs/retype.yml +++ b/docs/retype.yml @@ -3,7 +3,7 @@ output: .retype url: https://pocketpy.dev branding: title: pocketpy - label: v2.0.0 + label: v2.0.1 logo: "./static/logo.png" favicon: "./static/logo.png" meta: diff --git a/plugins/flutter/pocketpy/pubspec.yaml b/plugins/flutter/pocketpy/pubspec.yaml index d3286b3b..d26bdca0 100644 --- a/plugins/flutter/pocketpy/pubspec.yaml +++ b/plugins/flutter/pocketpy/pubspec.yaml @@ -1,6 +1,6 @@ name: pocketpy description: A lightweight Python interpreter for game engines. It supports Android/iOS/Windows/Linux/MacOS. -version: 2.0.1+6 +version: 2.0.1+7 homepage: https://pocketpy.dev repository: https://github.com/pocketpy/pocketpy diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index ff339812..a86343d9 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -2466,6 +2466,19 @@ static Error* compile_try_except(Compiler* self) { Ctx__emit_(ctx(), OP_TRY_ENTER, BC_NOARG, prev()->line); check(compile_block_body(self, compile_stmt)); + // https://docs.python.org/3/reference/compound_stmts.html#finally-clause + /* If finally is present, it specifies a ‘cleanup’ handler. The try clause is executed, + * including any except and else clauses. If an exception occurs in any of the clauses and is + * not handled, the exception is temporarily saved. The finally clause is executed. If there is + * a saved exception it is re-raised at the end of the finally clause. If the finally clause + * raises another exception, the saved exception is set as the context of the new exception. If + * the finally clause executes a return, break or continue statement, the saved exception is + * discarded. + */ + + // known issue: + // A return, break, continue in try/except block will make the finally block not executed + bool has_finally = curr()->type == TK_FINALLY; if(!has_finally) { patches[patches_length++] = Ctx__emit_(ctx(), OP_JUMP_FORWARD, BC_NOARG, BC_KEEPLINE);