diff --git a/S02-types/baggy.t b/S02-types/baggy.t index a74808aa97..14c8b75987 100644 --- a/S02-types/baggy.t +++ b/S02-types/baggy.t @@ -1,7 +1,7 @@ use v6; use Test; -plan 3; +plan 5; # Tests of the Baggy role @@ -12,3 +12,27 @@ plan 3; is-deeply $b.invert, (2 => "a", 1 => "b"), '.invert'; is-deeply $b.SetHash, SetHash.new(), '.SetHash'; } + +{ # RT#127863 + subtest 'cloned BagHash gets its own elements storage' => { + plan 2; + my $a = BagHash.new: ; + my $b = $a.clone; + $a--; $a++; $a = 42; + is-deeply $a, BagHash.new-from-pairs("b" => 2, "c" => 1, "z" => 42), + 'modifying first bag works, even after we created its clone'; + is-deeply $b, BagHash.new(), + 'modifying first bag does not affect cloned bag'; + } + + subtest 'cloned MixHash gets its own elements storage' => { + plan 2; + my $a = MixHash.new: ; + my $b = $a.clone; + $a--; $a++; $a = 42; + is-deeply $a, MixHash.new-from-pairs("b" => 2, "c" => 1, "z" => 42), + 'modifying first mix works, even after we created its clone'; + is-deeply $b, MixHash.new(), + 'modifying first mix does not affect cloned mix'; + } +} diff --git a/S02-types/sethash.t b/S02-types/sethash.t index 95db28cb44..9d6b06f3a1 100644 --- a/S02-types/sethash.t +++ b/S02-types/sethash.t @@ -1,7 +1,7 @@ use v6; use Test; -plan 209; +plan 210; # L @@ -477,4 +477,16 @@ subtest 'SetHash autovivification of non-existent keys' => { is-deeply $sh5, Bool::True, 'correct result of assignment'; } +# RT#127863 +subtest 'cloned SetHash gets its own elements storage' => { + plan 2; + my $a = SetHash.new: ; + my $b = $a.clone; + $a--; $a++; $a = 1; + is-deeply $a, SetHash.new-from-pairs("b" => 1, "c" => 1, "z" => 1), + 'modifying first set works, even after we created its clone'; + is-deeply $b, SetHash.new(), + 'modifying first set does not affect cloned set'; +} + # vim: ft=perl6