Skip to content

Commit

Permalink
Correct error msg for sub:lvalue{%h{k}} in sassign
Browse files Browse the repository at this point in the history
This:

    sub foo : lvalue { %hash{'key'} }
    foo = 3;

was incorrectly giving ‘Can't modify key/value hash slice in list
assignment’.  There is no list assignment there.
  • Loading branch information
Father Chrysostomos committed May 20, 2016
1 parent a061ab0 commit cc5f9b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pp.c
Expand Up @@ -5158,7 +5158,8 @@ PP(pp_kvhslice)
if (flags) {
if (!(flags & OPpENTERSUB_INARGS))
/* diag_listed_as: Can't modify %s in %s */
Perl_croak(aTHX_ "Can't modify key/value hash slice in list assignment");
Perl_croak(aTHX_ "Can't modify key/value hash slice in %s assignment",
GIMME_V == G_ARRAY ? "list" : "scalar");
lval = flags;
}
}
Expand Down
8 changes: 6 additions & 2 deletions t/op/kvhslice.t
Expand Up @@ -8,7 +8,7 @@ BEGIN {

# use strict;

plan tests => 39;
plan tests => 40;

# simple use cases
{
Expand Down Expand Up @@ -134,9 +134,13 @@ plan tests => 39;
# 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';
}
}

Expand Down

0 comments on commit cc5f9b8

Please sign in to comment.