This adds a major new ability to subroutine signatures, allowing callers
to pass parameters by name/value pairs rather than by position.
sub f ($x, $y, :$alpha, :$beta = undef) { ... }
f( 123, 456, alpha => 789 );
Originally specified in
https://github.com/Perl/PPCs/blob/main/ppcs/ppc0024-signature-named-parameters.md
This feature is currently considered experimental.
Function combines call of original `package` and `package_version` when
new namespace statement is detected.
Instead of required three statements usage now consists of single function call.
By defining a helper term for optional defaulting expression we can
remove one of the three alternate cases down to just two. This will help
when adding more code to these action blocks in future,
This simplifies potential callsites from other locations, avoiding their
need to create the special weird OP_ARGELEM fragments. Additionally this
decouples the knowledge that these operations are run on OP_ARGELEM ops
in the first place, allowing for a future version that operates
differently.
This fixes the TODO test in t/op/anonsub.t, but breaks two other tests:
- t/op/anonsub.t
not ok 12 - '{ $x = sub }' is illegal
# Failed test 12 - '{ $x = sub }' is illegal at t/op/anonsub.t line 15
# got 'Global symbol \"$x\" requires explicit package name (did you forget to declare \"my $x\"?) at (eval 12) line 1, <DATA> line 87.\nIllegal declaration of anonymous subroutine at (eval 12) line 1, at EOF\n'
# expected /(?^:^Illegal declaration of anonymous subroutine at)/
- t/lib/croak.t
FILE: lib/croak/toke ; line 644
PROG:
no feature 'apostrophe_as_package_separator';
sub 'Hello'_he_said (_);
EXPECTED:
Illegal declaration of anonymous subroutine at - line 2.
EXIT STATUS: != 0
GOT:
Bareword found where operator expected (Missing operator before "_he_said"?) at - line 2, near "'Hello'_he_said"
Illegal declaration of anonymous subroutine at - line 2, near "sub 'Hello'"
Execution of - aborted due to compilation errors.
EXIT STATUS: 255
not ok 247 - tick in names: initial character of sub name (no feature)
# Failed test 247 - tick in names: initial character of sub name (no feature) at lib/croak/toke line 644
Since we don't immediately error out from the lexer anymore, the parser
may accumulate more errors before failing with "Illegal declaration of
anonymous subroutine".
The tests have been changed to accomodate the new diagnostics.
Fixes#5959.
Provide a subsignature_*() API
Added:
* subsignature_start()
* subsignature_append_slurpy()
* subsignature_append_positional()
* subsignature_finish()
Call these from code blocks in perly.y
Make the actual parser signature struct opaque, hidden in toke.c. This
gives it much more robustness against future modifications.
As these only permit `any BLOCK LIST` and not the deferred-expression
form like `grep EXPR, LIST`, we create a whole new token type, BLKLSTOP,
to represent these. The parser then only accepts the block form and not
the expression form when parsing these.
The idea behind this code was to find the big enum block in perlytmp.h
that looks like:
enum yytokentype {
YYEMPTY = -2,
YYEOF = 0, /* "end of file" */
YYerror = 256, /* error */
YYUNDEF = 257, /* "invalid token" */
GRAMPROG = 258, /* GRAMPROG */
GRAMEXPR = 259, /* GRAMEXPR */
GRAMBLOCK = 260, /* GRAMBLOCK */
...
};
... and append to it (in perly.h) a series of equivalent macro
definitions, one for each (non-negative) enum symbol:
#define YYEOF 0
#define YYerror 256
#define YYUNDEF 257
#define GRAMPROG 258
#define GRAMEXPR 259
#define GRAMBLOCK 260
...
However, due to slight formatting changes in the code generated by bison
3+, this code has been essentially dead because the starting regex
didn't match anymore, so $gather_tokens was never set to a true value.
The last time we had token macros in perly.h was before commit
a9f5ab8de628 (in 2016), in which I generated perly.h using bison 3 for
the first time (without noticing the disappearance of the token macros).
We could try to fix the regex logic in regen_perly.pl, but given that no
one has complained about the missing token macros in 8 years (as far as
I know), let's just remove the code. (Yay, accidental scream tests?)
The reeproducer resulted in the "block" OP being both on the parser
stack and attacked to the CV. If an error occurred while parsing the
rest of the list operator clean up would release the OP as attached
to the CV, and the same OP on the parse stack, resulting in a double
free.
It's unclear to me whether bison is intended to support modifying
the parse stack entry like this, but it appears to work here.
Fixes#21724
Previously, the low-precedence `xor` operator did not have a
higher-precedence logical variant, as compared `or` vs `||` and
`and` vs `&&`. This PR adds such an operator syntax, completing the
set.
Using class attributes in the unit class syntax was a syntax error. This change makes the following two lines equivalent:
class B :isa(A) ;
class B :isa(A) { }
Addresses GH issue #20888.
This is a companion patch to the previous one, it is generated with a
slightly more modern Bison which produces better indented output, and
puts parens around constant defines and other minor changes. It is
recommended to view this patch with the -w option to skip most of the
the "non change" changes it contains.
* Free the attrlist OP fragment when applying class or field attribute
* Free the OP_PADxV ops we only use to get the pad index out for
fieldvar declarations
* Add a refcount to the `struct padname_fieldinfo` to keep track of its
capture in inner closures so it can be freed at the right time
* Free the class-related fields out of HvAUX
* Free the actual ObjectFIELDS() array when destroying an object instance
* Dup fieldinfo->paramname at sv_dup() time / free it at free time