Remove support for implicit 'exception' name in 'except' blocks

This commit is contained in:
K. Lange 2023-11-25 12:30:52 +09:00
parent d575bf7607
commit fb6faaff1a
2 changed files with 7 additions and 6 deletions

View File

@ -2290,22 +2290,23 @@ _anotherExcept:
nextJump = emitJump(OP_FILTER_EXCEPT); nextJump = emitJump(OP_FILTER_EXCEPT);
/* Match 'as' to rename exception */ /* Match 'as' to rename exception */
size_t nameInd = 0;
if (match(TOKEN_AS)) { if (match(TOKEN_AS)) {
consume(TOKEN_IDENTIFIER, "Expected identifier after 'as'."); consume(TOKEN_IDENTIFIER, "Expected identifier after 'as'.");
state->current->locals[exceptionObject].name = state->parser.previous; state->current->locals[exceptionObject].name = state->parser.previous;
/* `renameLocal` only introduces names for scoped debugging */
nameInd = renameLocal(state, exceptionObject, state->parser.previous);
} else { } else {
/* XXX Should we remove this now? */ state->current->locals[exceptionObject].name = syntheticToken("");
state->current->locals[exceptionObject].name = syntheticToken("exception");
} }
size_t nameInd = renameLocal(state, exceptionObject, state->current->locals[exceptionObject].name);
consume(TOKEN_COLON, "Expected ':' after 'except'."); consume(TOKEN_COLON, "Expected ':' after 'except'.");
beginScope(state); beginScope(state);
block(state,blockWidth,"except"); block(state,blockWidth,"except");
endScope(state); 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) { if (exitJumps < EXIT_JUMP_MAX) {
exitJumpOffsets[exitJumps++] = emitJump(OP_JUMP); exitJumpOffsets[exitJumps++] = emitJump(OP_JUMP);

2
src/vendor/rline.c vendored
View File

@ -560,7 +560,7 @@ static char * syn_krk_types[] = {
"self", "super", /* implicit in a class method */ "self", "super", /* implicit in a class method */
"len", "str", "int", "float", "dir", "repr", /* global functions from __builtins__ */ "len", "str", "int", "float", "dir", "repr", /* global functions from __builtins__ */
"list","dict","range", /* builtin classes */ "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", "print","set","any","all","bool","ord","chr","hex","oct","filter",
"sorted","bytes","getattr","sum","min","max","id","hash","map","bin", "sorted","bytes","getattr","sum","min","max","id","hash","map","bin",
"enumerate","zip","setattr","property","staticmethod","classmethod", "enumerate","zip","setattr","property","staticmethod","classmethod",