Perl5-IDEA icon indicating copy to clipboard operation
Perl5-IDEA copied to clipboard

Make call parameters mutation inspection

Open hurricup opened this issue 3 years ago • 0 comments

Mutating elements of @_ causes mutating of passed parameters and fails if passed parameter is RO. Inspection should show such problems.

Example illustrating the issue:

use strict;
use warnings FATAL => 'all';
use v5.10;

package Foo::Bar;

sub new {
    bless {}, 'Foo::Bar';
}

sub foo {
    # First way
    $_[0] = -1;

    # Second way
    @_[1] = (-2);

    # Third way
    my $argref = \@_;
    $argref->[2] = -3;

    # Forth way
    $argref = \$_[3];
    $$argref = -4;
}

package main;

my $obj = Foo::Bar->new();
my @args = (1,2,3);
say join ', ', $obj, @args;
$obj->foo(@args);
say join ', ', $obj, @args;

hurricup avatar Apr 24 '22 12:04 hurricup