From fb6faaff1a2305d0d557ab0a9f1142b4ad97a8ef Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sat, 25 Nov 2023 12:30:52 +0900 Subject: [PATCH] Remove support for implicit 'exception' name in 'except' blocks --- src/compiler.c | 11 ++++++----- src/vendor/rline.c | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/compiler.c b/src/compiler.c index 3370dd4..517062d 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -2290,22 +2290,23 @@ _anotherExcept: nextJump = emitJump(OP_FILTER_EXCEPT); /* Match 'as' to rename exception */ + size_t nameInd = 0; if (match(TOKEN_AS)) { consume(TOKEN_IDENTIFIER, "Expected identifier after 'as'."); state->current->locals[exceptionObject].name = state->parser.previous; + /* `renameLocal` only introduces names for scoped debugging */ + nameInd = renameLocal(state, exceptionObject, state->parser.previous); } else { - /* XXX Should we remove this now? */ - state->current->locals[exceptionObject].name = syntheticToken("exception"); + state->current->locals[exceptionObject].name = syntheticToken(""); } - size_t nameInd = renameLocal(state, exceptionObject, state->current->locals[exceptionObject].name); - consume(TOKEN_COLON, "Expected ':' after 'except'."); beginScope(state); block(state,blockWidth,"except"); endScope(state); - state->current->codeobject->localNames[nameInd].deathday = (size_t)currentChunk()->count; + /* Remove scoped name */ + if (nameInd) state->current->codeobject->localNames[nameInd].deathday = (size_t)currentChunk()->count; if (exitJumps < EXIT_JUMP_MAX) { exitJumpOffsets[exitJumps++] = emitJump(OP_JUMP); diff --git a/src/vendor/rline.c b/src/vendor/rline.c index 8859b1d..5c16e89 100644 --- a/src/vendor/rline.c +++ b/src/vendor/rline.c @@ -560,7 +560,7 @@ static char * syn_krk_types[] = { "self", "super", /* implicit in a class method */ "len", "str", "int", "float", "dir", "repr", /* global functions from __builtins__ */ "list","dict","range", /* builtin classes */ - "object","exception","isinstance","type","tuple","reversed", + "object","isinstance","type","tuple","reversed", "print","set","any","all","bool","ord","chr","hex","oct","filter", "sorted","bytes","getattr","sum","min","max","id","hash","map","bin", "enumerate","zip","setattr","property","staticmethod","classmethod",