Skip to content

Commit 6868eea

Browse files
tonycozap
authored andcommitted
implement the smartmatch feature and test it
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
1 parent ed1ae14 commit 6868eea

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6131,6 +6131,7 @@ t/lib/feature/multidimensional Tests for enabling/disabling $foo{$x, $y} => $fo
61316131
t/lib/feature/nonesuch Tests for enabling/disabling nonexistent feature
61326132
t/lib/feature/removed Tests for enabling/disabling removed feature
61336133
t/lib/feature/say Tests for enabling/disabling say feature
6134+
t/lib/feature/smartmatch Tests for enabling/disabling smartmatch feature
61346135
t/lib/feature/switch Tests for enabling/disabling switch feature
61356136
t/lib/h2ph.h Test header file for h2ph
61366137
t/lib/h2ph.pht Generated output from h2ph.h by h2ph, for comparison

t/lib/feature/smartmatch

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Test no feature smartmatch
2+
3+
__END__
4+
# NAME default
5+
my @x = qw(a b c);
6+
my $y = "b" ~~ @x;
7+
EXPECT
8+
Smartmatch is deprecated at - line 2.
9+
########
10+
# NAME explicit disable
11+
no feature "smartmatch";
12+
my @x = qw(a b c);
13+
my $y = "b" ~~ @x;
14+
EXPECT
15+
OPTION fatal
16+
syntax error at - line 3, near ""b" ~"
17+
Execution of - aborted due to compilation errors.
18+
########
19+
# NAME explicit enable
20+
use feature "smartmatch";
21+
my @x = qw(a b c);
22+
my $y = "b" ~~ @x;
23+
EXPECT
24+
Smartmatch is deprecated at - line 3.
25+
########
26+
# NAME explicit disable then enable
27+
no feature "smartmatch";
28+
use feature "smartmatch";
29+
my @x = qw(a b c);
30+
my $y = "b" ~~ @x;
31+
EXPECT
32+
Smartmatch is deprecated at - line 4.
33+
########
34+
# NAME implicit disable
35+
use v5.41;
36+
my @x = qw(a b c);
37+
my $y = "b" ~~ @x;
38+
EXPECT
39+
OPTION fatal
40+
syntax error at - line 3, near ""b" ~"
41+
Execution of - aborted due to compilation errors.
42+
########
43+
# NAME implicit disable then enable
44+
use v5.41;
45+
use feature "smartmatch";
46+
my @x = qw(a b c);
47+
my $y = "b" ~~ @x;
48+
EXPECT
49+
Smartmatch is deprecated at - line 4.

toke.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6775,7 +6775,8 @@ static int
67756775
yyl_tilde(pTHX_ char *s)
67766776
{
67776777
bool bof;
6778-
if (s[1] == '~' && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)) {
6778+
if (FEATURE_SMARTMATCH_IS_ENABLED &&
6779+
s[1] == '~' && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)) {
67796780
if (!PL_lex_allbrackets && PL_lex_fakeeof >= LEX_FAKEEOF_COMPARE)
67806781
TOKEN(0);
67816782
s += 2;

0 commit comments

Comments
 (0)