You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Edit: See next comment for a related problem where refs-to-refs aren't readonly]
If the thing being Readonly::Cloned is a ref-to-scalar, you get back the scalar, without the reference:
#!/usr/bin/perl
use strict; use warnings; use feature 'say';
use Data::Dumper;
use Readonly ();
my $foo = 42;
my $original = \$foo;
my $copy = Readonly::Clone($original);
say Data::Dumper->new([$original,$copy],["original","copy"])->Dump;
RESULTS:
$original = \42;
$copy = 42;
I'm assuming Readonly::Clone() is intended to have the same API as Clone::clone().
Using Readonly 2.05 with Perl v5.34.0
The text was updated successfully, but these errors were encountered:
There may be a more general bug with how references to other references are handled (i.e. not just at the top level). It seems like the refs themselves are not made read-only, nor anything they point to.
Here is an example of a "read only" structure which is actually mutuable:
#!/usr/bin/env perl
use strict; use warnings; use feature qw/say/;
use Data::Dumper; $Data::Dumper::Indent = 0;
use Readonly ();
Readonly::Scalar my $roitem => { foo => \\\{ bar => 42 } };
say Data::Dumper->new([$roitem],['roitem'])->Dump;
$$${$roitem->{foo}}->{bar} += 1000; # SHOULD DIE HERE?
say Data::Dumper->new([$roitem],['roitem'])->Dump;
${$roitem->{foo}} = "something else"; # SHOULD DIE HERE?
say Data::Dumper->new([$roitem],['roitem'])->Dump;
jimav
changed the title
Readonly::Clone corrupts top-level reference-to-scalar (looses the ref)
Refs-to-refs not handled correctly (or at least as I expected)
May 3, 2023
[Edit: See next comment for a related problem where refs-to-refs aren't readonly]
If the thing being
Readonly::Clone
d is a ref-to-scalar, you get back the scalar, without the reference:RESULTS:
I'm assuming Readonly::Clone() is intended to have the same API as Clone::clone().
Using Readonly 2.05 with Perl v5.34.0
The text was updated successfully, but these errors were encountered: