summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2019-09-23 15:22:11 +0100
committerDavid Mitchell <davem@iabyn.com>2019-09-23 15:27:43 +0100
commitf27832e79a0b43f3b2bded8020491011faa617c7 (patch)
tree819a69dabe54b50728fd6565295af1cee9815ee7 /t
parent4df857782a14d0973f58f6a629019d29259b2aad (diff)
downloadperl-f27832e79a0b43f3b2bded8020491011faa617c7.tar.gz
sub foo($_) {...} - change error message
When using one of the globals like $_ or @_ in a subroutine signature, the error message was misleading: Can't use global $_ in "my" This commit changes it to: Can't use global $_ in subroutine signature
Diffstat (limited to 't')
-rw-r--r--t/op/signatures.t17
1 files changed, 15 insertions, 2 deletions
diff --git a/t/op/signatures.t b/t/op/signatures.t
index a2dad424af..80fde83cff 100644
--- a/t/op/signatures.t
+++ b/t/op/signatures.t
@@ -1126,10 +1126,10 @@ syntax error at foo line 8, near "\$\$) "
EOF
eval "#line 8 foo\nsub t101 (\@_) { }";
-like $@, qr/\ACan't use global \@_ in "my" at foo line 8/;
+like $@, qr/\ACan't use global \@_ in subroutine signature at foo line 8/;
eval "#line 8 foo\nsub t102 (\%_) { }";
-like $@, qr/\ACan't use global \%_ in "my" at foo line 8/;
+like $@, qr/\ACan't use global \%_ in subroutine signature at foo line 8/;
my $t103 = sub ($a) { $a || "z" };
is prototype($t103), undef;
@@ -1575,6 +1575,19 @@ while(<$kh>) {
like $warn[3], qr/line 8,/, 'multiline1: $e';
}
+# check errors for using global vars as params
+
+{
+ eval q{ sub ($_) {} };
+ like $@, qr/Can't use global \$_ in subroutine signature/, 'f($_)';
+ eval q{ sub (@_) {} };
+ like $@, qr/Can't use global \@_ in subroutine signature/, 'f(@_)';
+ eval q{ sub (%_) {} };
+ like $@, qr/Can't use global \%_ in subroutine signature/, 'f(%_)';
+ eval q{ sub ($1) {} };
+ like $@, qr/Illegal operator following parameter in a subroutine signature/,
+ 'f($1)';
+}
done_testing;