[perl #124057] [SEGV] Proxy class attribute interaction segfaults
[email protected] ("Ron Schmidt via RT") Wed, 14 Mar 2018 10:44:56 -0700
| Newsgroups | perl.perl6.compiler |
|---|---|
| Message-ID | <[email protected]> |
When I run this example now (Windows and Linux) I get:
P6opaque: no such attribute '$!encoded-string' on type Codeword in a Proxy when trying to get a value
instead of a segfault. If I tweak the code as below to use subs instead of methods for the Proxy hooks it runs fine. The P6opaque error seems reminiscent of a recent IRC conversation: https://irclog.perlgeek.de/perl6/2018-03-03#i_15879434 . Between the IRC conversation and making it work by switching to subs I suspect it might be OK to merge this ticket with RT 126198 .
## codeword.p6
class Codeword {
has Sub $.scrambler is rw;
has $!string;
has Str $!encoded-string;
submethod BUILD {
my sub scrambler { $^s.trans: 'a..mn..z' => 'n..za..m', :ii }
$!scrambler = &scrambler;
}
method codeword returns Str is rw {
return Proxy.new(
FETCH => sub ($) { $!encoded-string },
STORE => sub ($,$s) { $!encoded-string = $!scrambler($s) }
);
}
}
my $code = Codeword.new;
$code.codeword;
$code.codeword = 'abc';
say $code.codeword;
> prints
nop