I have a role. For the sake of this discussion, let's say it looks like this:
role F {
has FType $!f
method !setObject ($obj) {
say '---F';
say "SetObject ({ self }): { $obj }";
$!o = $obj ~~ F ?? $obj !! cast(F, $obj);
say "ObjectSet ({ self }): { $!o }";
}
method F ( :object(:$obj) ) { say 'F---'; $obj ?? self !! $!o }
}
Seems fairly straight forward, correct? Let's add an object that consumes it:
class Consumes::F {
also does F;
# cw: This method included in full
method setConsumesF ($_) {
my $param = $_;
my $to-parent;
say "setConsumesF Param: $param";
$!ios = do {
when Consumes::F {
$to-parent = cast(F, $param);
$param;
}
default {
$to-parent = $param;
cast(F, $param);
}
}
say "ConsumesF Set: $!ios";
say "ConsumesF Parent: $to-parent";
self!setObject($to-parent);
say "F GObject { self.F }";
$!o = $to-parent;
say "F Object2 { self.F }";
say "F Object3 { $!o }";
}
}
When I attmpt to run the code this is based on, I get something like this;
ConsumesF Param: ConsumesF<94718917380240>
ConsumesF Set: ConsumesF<94718917380240>
GIOStream Parent: F<94718906041344>
SetObject (F<94718906041344>): ConnsumesF<94718906041344>
ObjectSet (F<94718906041344>): ConnsumesF<94718906041344>
GObject---
Use of uninitialized value of type FType in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
in method setConsumesF
F Object
F---
Use of uninitialized value of type FType in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
in method setConsumesF
F Object2
F Object3 F<94718906041344>
The key point here is that between the SetObject
and ObjectSet
markers, the attribute is set. The value on the ObjectSet
shows that the assignment took place.
However, one we leve that scope, the value for $!f
mysteriously reverts back, as shown by the 'Use of uninitialized value'
errors. I've repeated this pattern over and over in the Larger Body of Code I am working from, however there is this single instance when Rakudo apparenltly is not Doing What I Mean. It is in fact doing Something but Ultimately Nothing. It is the thing that it is supposed to be doing (setting the attribute) and not (retrieving an undefined value) that has me worried.
I hope it's a bug in my code. Could someone look at it and tell me where I am going wrong?