Skip to content

Commit 1fa9ddf

Browse files
committed
test for RT #71356: readonly trait for private attributes
1 parent b8d4388 commit 1fa9ddf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

S06-traits/is-readonly.t

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 12;
4+
plan 14;
55

66
# L<S06/"Parameter traits"/"=item is readonly">
77
# should be moved with other subroutine tests?
@@ -54,4 +54,15 @@ plan 12;
5454
'dies on assignment to (my $x is readonly)';
5555
}
5656

57+
# RT #71356
58+
{
59+
class C {
60+
has $!attr is readonly = 71356;
61+
method get-attr() { $!attr }
62+
method set-attr($val) { $!attr = $val }
63+
}
64+
is C.new.get-attr, 71356, 'can read from readonly private attributes';
65+
dies_ok { my $c = C.new; $c.set-attr: 99; }, 'cannot assign to readonly private attribute'
66+
}
67+
5768
# vim: ft=perl6

0 commit comments

Comments
 (0)