Skip to content

Commit

Permalink
implement the smartmatch feature and test it
Browse files Browse the repository at this point in the history
interestingly the TOKEN(0) line here isn't exercised by the test
suite, I haven't tracked down what it would take to exercise it.

The deprecation messages will be removed in an upcoming commit
  • Loading branch information
tonycoz authored and ap committed Feb 16, 2025
1 parent ed1ae14 commit 6868eea
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -6131,6 +6131,7 @@ t/lib/feature/multidimensional Tests for enabling/disabling $foo{$x, $y} => $fo
t/lib/feature/nonesuch Tests for enabling/disabling nonexistent feature
t/lib/feature/removed Tests for enabling/disabling removed feature
t/lib/feature/say Tests for enabling/disabling say feature
t/lib/feature/smartmatch Tests for enabling/disabling smartmatch feature
t/lib/feature/switch Tests for enabling/disabling switch feature
t/lib/h2ph.h Test header file for h2ph
t/lib/h2ph.pht Generated output from h2ph.h by h2ph, for comparison
Expand Down
49 changes: 49 additions & 0 deletions t/lib/feature/smartmatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Test no feature smartmatch

__END__
# NAME default
my @x = qw(a b c);
my $y = "b" ~~ @x;
EXPECT
Smartmatch is deprecated at - line 2.
########
# NAME explicit disable
no feature "smartmatch";
my @x = qw(a b c);
my $y = "b" ~~ @x;
EXPECT
OPTION fatal
syntax error at - line 3, near ""b" ~"
Execution of - aborted due to compilation errors.
########
# NAME explicit enable
use feature "smartmatch";
my @x = qw(a b c);
my $y = "b" ~~ @x;
EXPECT
Smartmatch is deprecated at - line 3.
########
# NAME explicit disable then enable
no feature "smartmatch";
use feature "smartmatch";
my @x = qw(a b c);
my $y = "b" ~~ @x;
EXPECT
Smartmatch is deprecated at - line 4.
########
# NAME implicit disable
use v5.41;
my @x = qw(a b c);
my $y = "b" ~~ @x;
EXPECT
OPTION fatal
syntax error at - line 3, near ""b" ~"
Execution of - aborted due to compilation errors.
########
# NAME implicit disable then enable
use v5.41;
use feature "smartmatch";
my @x = qw(a b c);
my $y = "b" ~~ @x;
EXPECT
Smartmatch is deprecated at - line 4.
3 changes: 2 additions & 1 deletion toke.c
Original file line number Diff line number Diff line change
Expand Up @@ -6775,7 +6775,8 @@ static int
yyl_tilde(pTHX_ char *s)
{
bool bof;
if (s[1] == '~' && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)) {
if (FEATURE_SMARTMATCH_IS_ENABLED &&
s[1] == '~' && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)) {
if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
TOKEN(0);
s += 2;
Expand Down

0 comments on commit 6868eea

Please sign in to comment.