This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Rename a variable
[perl5.git] / t / op / kvhslice.t
index a5357ad..e3309ef 100644 (file)
@@ -8,7 +8,7 @@ BEGIN {
 
 # use strict;
 
-plan tests => 40;
+plan tests => 39;
 
 # simple use cases
 {
@@ -117,13 +117,6 @@ plan tests => 40;
         like $@, qr{^Can't modify key/value hash slice in local at},
             'local dies';
     }
-    # no delete
-    {
-        local $@;
-        eval 'delete %h{qw(a b)}';
-        like $@, qr{^delete argument is key/value hash slice, use hash slice},
-            'delete dies';
-    }
     # no assign
     {
         local $@;
@@ -134,9 +127,13 @@ plan tests => 40;
     # lvalue subs in assignment
     {
         local $@;
-        eval 'sub bar:lvalue{ %h{qw(a b)} }; bar() = "1"';
+        eval 'sub bar:lvalue{ %h{qw(a b)} }; (bar) = "1"';
         like $@, qr{^Can't modify key/value hash slice in list assignment},
             'not allowed as result of lvalue sub';
+        eval 'sub bbar:lvalue{ %h{qw(a b)} }; bbar() = "1"';
+        like $@,
+             qr{^Can't modify key/value hash slice in scalar assignment},
+            'not allowed as result of lvalue sub';
     }
 }
 
@@ -184,17 +181,19 @@ plan tests => 40;
     ok( !exists $h{e}, "no autovivification" );
 }
 
-# keys/value/each treat argument as scalar
+# keys/value/each refuse to compile kvhslice
 {
     my %h = 'a'..'b';
     my %i = (foo => \%h);
-    no warnings 'syntax', 'experimental::autoderef';
-    my ($k,$v) = each %i{foo=>};
-    is $k, 'a', 'key returned by each %hash{key}';
-    is $v, 'b', 'val returned by each %hash{key}';
-    %h = 1..10;
-    is join('-', sort keys %i{foo=>}), '1-3-5-7-9', 'keys %hash{key}';
-    is join('-', sort values %i{foo=>}), '10-2-4-6-8', 'values %hash{key}';
+    eval '() = keys %i{foo=>}';
+    like($@, qr/Experimental keys on scalar is now forbidden/,
+         'keys %hash{key} forbidden');
+    eval '() = values %i{foo=>}';
+    like($@, qr/Experimental values on scalar is now forbidden/,
+         'values %hash{key} forbidden');
+    eval '() = each %i{foo=>}';
+    like($@, qr/Experimental each on scalar is now forbidden/,
+         'each %hash{key} forbidden');
 }
 
 # \% prototype expects hash deref