From f8245cd9653db9b3e3fef57c3913d9deb33972b2 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Sat, 16 Apr 2022 11:48:20 +0100 Subject: for my ($x) ...: fix handling of degenerate 1-var The new for my ($x,$y,...) (...) { ... } syntax has a couple of problems in the degenerate case of a single variable: for my ($x) (...) { ... } First, the loop variable is marked as lexical, but not as a variable to be introduced. So it behaves roughly as if written like: { my $x; for $x (...) { ... } } I can't think of any user-visible runtime change in behaviour this bug causes, so I haven't included a test for it. Second, it was being incorrectly deparsed as for $x (...) { ... } (i.e. without the 'my'). This commit fixes both of these issues. The basic problem is that the parser, in the case of multiple vars, passes a list subtree of PADSVs as the 'sv' argument of Perl_newFOROP, but in the case of a single var, passes a single PADSV op instead. This single PADSV doesn't have the LVINTRO flag set, so is indistinguishable from plain my $x; for $x .... This commit makes the parser set the OPf_PARENS flag on the lone PADSV to signal to newFOROP() that it's a degenerate 1-var list, and newFOROP() sets the OPf_PARENS flag on the ENTERITER op to signal to the deparser that this is "for my (...)" syntax, even if it only has a single var. --- perly.h | 247 +++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 126 insertions(+), 121 deletions(-) (limited to 'perly.h') diff --git a/perly.h b/perly.h index 9628138a37..d5a45b2a9c 100644 --- a/perly.h +++ b/perly.h @@ -4,14 +4,14 @@ Any changes made here will be lost! */ -#define PERL_BISON_VERSION 30003 +#define PERL_BISON_VERSION 30006 #ifdef PERL_CORE -/* A Bison parser, made by GNU Bison 3.3. */ +/* A Bison parser, made by GNU Bison 3.6.4. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -40,8 +40,9 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ /* Debug traces. */ #ifndef YYDEBUG @@ -51,124 +52,129 @@ extern int yydebug; #endif -/* Token type. */ +/* Token kinds. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE enum yytokentype { - GRAMPROG = 258, - GRAMEXPR = 259, - GRAMBLOCK = 260, - GRAMBARESTMT = 261, - GRAMFULLSTMT = 262, - GRAMSTMTSEQ = 263, - GRAMSUBSIGNATURE = 264, - PERLY_AMPERSAND = 265, - PERLY_BRACE_OPEN = 266, - PERLY_BRACE_CLOSE = 267, - PERLY_BRACKET_OPEN = 268, - PERLY_BRACKET_CLOSE = 269, - PERLY_COMMA = 270, - PERLY_DOLLAR = 271, - PERLY_DOT = 272, - PERLY_EQUAL_SIGN = 273, - PERLY_MINUS = 274, - PERLY_PERCENT_SIGN = 275, - PERLY_PLUS = 276, - PERLY_SEMICOLON = 277, - PERLY_SLASH = 278, - PERLY_SNAIL = 279, - PERLY_STAR = 280, - BAREWORD = 281, - METHOD = 282, - FUNCMETH = 283, - THING = 284, - PMFUNC = 285, - PRIVATEREF = 286, - QWLIST = 287, - FUNC0OP = 288, - FUNC0SUB = 289, - UNIOPSUB = 290, - LSTOPSUB = 291, - PLUGEXPR = 292, - PLUGSTMT = 293, - LABEL = 294, - FORMAT = 295, - SUB = 296, - SIGSUB = 297, - ANONSUB = 298, - ANON_SIGSUB = 299, - PACKAGE = 300, - USE = 301, - WHILE = 302, - UNTIL = 303, - IF = 304, - UNLESS = 305, - ELSE = 306, - ELSIF = 307, - CONTINUE = 308, - FOR = 309, - GIVEN = 310, - WHEN = 311, - DEFAULT = 312, - TRY = 313, - CATCH = 314, - FINALLY = 315, - LOOPEX = 316, - DOTDOT = 317, - YADAYADA = 318, - FUNC0 = 319, - FUNC1 = 320, - FUNC = 321, - UNIOP = 322, - LSTOP = 323, - MULOP = 324, - ADDOP = 325, - DOLSHARP = 326, - DO = 327, - HASHBRACK = 328, - NOAMP = 329, - LOCAL = 330, - MY = 331, - REQUIRE = 332, - COLONATTR = 333, - FORMLBRACK = 334, - FORMRBRACK = 335, - SUBLEXSTART = 336, - SUBLEXEND = 337, - DEFER = 338, - PREC_LOW = 339, - OROP = 340, - ANDOP = 341, - NOTOP = 342, - ASSIGNOP = 343, - PERLY_QUESTION_MARK = 344, - PERLY_COLON = 345, - OROR = 346, - DORDOR = 347, - ANDAND = 348, - BITOROP = 349, - BITANDOP = 350, - CHEQOP = 351, - NCEQOP = 352, - CHRELOP = 353, - NCRELOP = 354, - SHIFTOP = 355, - MATCHOP = 356, - PERLY_EXCLAMATION_MARK = 357, - PERLY_TILDE = 358, - UMINUS = 359, - REFGEN = 360, - POWOP = 361, - PREINC = 362, - PREDEC = 363, - POSTINC = 364, - POSTDEC = 365, - POSTJOIN = 366, - ARROW = 367, - PERLY_PAREN_CLOSE = 368, - PERLY_PAREN_OPEN = 369 + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + GRAMPROG = 258, /* GRAMPROG */ + GRAMEXPR = 259, /* GRAMEXPR */ + GRAMBLOCK = 260, /* GRAMBLOCK */ + GRAMBARESTMT = 261, /* GRAMBARESTMT */ + GRAMFULLSTMT = 262, /* GRAMFULLSTMT */ + GRAMSTMTSEQ = 263, /* GRAMSTMTSEQ */ + GRAMSUBSIGNATURE = 264, /* GRAMSUBSIGNATURE */ + PERLY_AMPERSAND = 265, /* PERLY_AMPERSAND */ + PERLY_BRACE_OPEN = 266, /* PERLY_BRACE_OPEN */ + PERLY_BRACE_CLOSE = 267, /* PERLY_BRACE_CLOSE */ + PERLY_BRACKET_OPEN = 268, /* PERLY_BRACKET_OPEN */ + PERLY_BRACKET_CLOSE = 269, /* PERLY_BRACKET_CLOSE */ + PERLY_COMMA = 270, /* PERLY_COMMA */ + PERLY_DOLLAR = 271, /* PERLY_DOLLAR */ + PERLY_DOT = 272, /* PERLY_DOT */ + PERLY_EQUAL_SIGN = 273, /* PERLY_EQUAL_SIGN */ + PERLY_MINUS = 274, /* PERLY_MINUS */ + PERLY_PERCENT_SIGN = 275, /* PERLY_PERCENT_SIGN */ + PERLY_PLUS = 276, /* PERLY_PLUS */ + PERLY_SEMICOLON = 277, /* PERLY_SEMICOLON */ + PERLY_SLASH = 278, /* PERLY_SLASH */ + PERLY_SNAIL = 279, /* PERLY_SNAIL */ + PERLY_STAR = 280, /* PERLY_STAR */ + BAREWORD = 281, /* BAREWORD */ + METHOD = 282, /* METHOD */ + FUNCMETH = 283, /* FUNCMETH */ + THING = 284, /* THING */ + PMFUNC = 285, /* PMFUNC */ + PRIVATEREF = 286, /* PRIVATEREF */ + QWLIST = 287, /* QWLIST */ + FUNC0OP = 288, /* FUNC0OP */ + FUNC0SUB = 289, /* FUNC0SUB */ + UNIOPSUB = 290, /* UNIOPSUB */ + LSTOPSUB = 291, /* LSTOPSUB */ + PLUGEXPR = 292, /* PLUGEXPR */ + PLUGSTMT = 293, /* PLUGSTMT */ + LABEL = 294, /* LABEL */ + FORMAT = 295, /* FORMAT */ + SUB = 296, /* SUB */ + SIGSUB = 297, /* SIGSUB */ + ANONSUB = 298, /* ANONSUB */ + ANON_SIGSUB = 299, /* ANON_SIGSUB */ + PACKAGE = 300, /* PACKAGE */ + USE = 301, /* USE */ + WHILE = 302, /* WHILE */ + UNTIL = 303, /* UNTIL */ + IF = 304, /* IF */ + UNLESS = 305, /* UNLESS */ + ELSE = 306, /* ELSE */ + ELSIF = 307, /* ELSIF */ + CONTINUE = 308, /* CONTINUE */ + FOR = 309, /* FOR */ + GIVEN = 310, /* GIVEN */ + WHEN = 311, /* WHEN */ + DEFAULT = 312, /* DEFAULT */ + TRY = 313, /* TRY */ + CATCH = 314, /* CATCH */ + FINALLY = 315, /* FINALLY */ + LOOPEX = 316, /* LOOPEX */ + DOTDOT = 317, /* DOTDOT */ + YADAYADA = 318, /* YADAYADA */ + FUNC0 = 319, /* FUNC0 */ + FUNC1 = 320, /* FUNC1 */ + FUNC = 321, /* FUNC */ + UNIOP = 322, /* UNIOP */ + LSTOP = 323, /* LSTOP */ + MULOP = 324, /* MULOP */ + ADDOP = 325, /* ADDOP */ + DOLSHARP = 326, /* DOLSHARP */ + DO = 327, /* DO */ + HASHBRACK = 328, /* HASHBRACK */ + NOAMP = 329, /* NOAMP */ + LOCAL = 330, /* LOCAL */ + MY = 331, /* MY */ + REQUIRE = 332, /* REQUIRE */ + COLONATTR = 333, /* COLONATTR */ + FORMLBRACK = 334, /* FORMLBRACK */ + FORMRBRACK = 335, /* FORMRBRACK */ + SUBLEXSTART = 336, /* SUBLEXSTART */ + SUBLEXEND = 337, /* SUBLEXEND */ + DEFER = 338, /* DEFER */ + PREC_LOW = 339, /* PREC_LOW */ + OROP = 340, /* OROP */ + ANDOP = 341, /* ANDOP */ + NOTOP = 342, /* NOTOP */ + ASSIGNOP = 343, /* ASSIGNOP */ + PERLY_QUESTION_MARK = 344, /* PERLY_QUESTION_MARK */ + PERLY_COLON = 345, /* PERLY_COLON */ + OROR = 346, /* OROR */ + DORDOR = 347, /* DORDOR */ + ANDAND = 348, /* ANDAND */ + BITOROP = 349, /* BITOROP */ + BITANDOP = 350, /* BITANDOP */ + CHEQOP = 351, /* CHEQOP */ + NCEQOP = 352, /* NCEQOP */ + CHRELOP = 353, /* CHRELOP */ + NCRELOP = 354, /* NCRELOP */ + SHIFTOP = 355, /* SHIFTOP */ + MATCHOP = 356, /* MATCHOP */ + PERLY_EXCLAMATION_MARK = 357, /* PERLY_EXCLAMATION_MARK */ + PERLY_TILDE = 358, /* PERLY_TILDE */ + UMINUS = 359, /* UMINUS */ + REFGEN = 360, /* REFGEN */ + POWOP = 361, /* POWOP */ + PREINC = 362, /* PREINC */ + PREDEC = 363, /* PREDEC */ + POSTINC = 364, /* POSTINC */ + POSTDEC = 365, /* POSTDEC */ + POSTJOIN = 366, /* POSTJOIN */ + ARROW = 367, /* ARROW */ + PERLY_PAREN_CLOSE = 368, /* PERLY_PAREN_CLOSE */ + PERLY_PAREN_OPEN = 369 /* PERLY_PAREN_OPEN */ }; + typedef enum yytokentype yytoken_kind_t; #endif /* Value type. */ @@ -197,7 +203,6 @@ S_is_opval_token(int type) { #endif /* PERL_IN_TOKE_C */ #endif /* PERL_CORE */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED - union YYSTYPE { @@ -207,8 +212,8 @@ union YYSTYPE OP *opval; GV *gvval; -}; +}; typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 @@ -220,6 +225,6 @@ int yyparse (void); /* Generated from: - * 979ab61527f6e4f14a05dffe99d51369abd1074d798becee74bedc780e3b519a perly.y + * 0caf1eb1cc4750131dc71e3a22ead383ed9a123dec61ccd23408ff13441fafde perly.y * acf1cbfd2545faeaaa58b1cf0cf9d7f98b5be0752eb7a54528ef904a9e2e1ca7 regen_perly.pl * ex: set ro: */ -- cgit v1.2.1