# New Ticket Created by  "Carl Mäsak" 
# Please include the string:  [perl #126198]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=126198 >


moritz++' gist inlined for your convenience:

our $count = 0;

class MagicVal {
    has Int $.constant;
    has Int $.varies = 0;

    method varies is rw {
        $count++;
        return-rw Proxy.new(
            # note that FETCH and STORE cannot go through the accessors
            # of $.varies again, because that would lead to infinite
            # recursion. Use the actual attribute here instead
            FETCH => method ()     { $!varies  },
            STORE => method ($new) { $!varies = $new + 1 },
        );
    }
}

my $mv = MagicVal.new(:constant(6), :varies(6));
say $mv.varies.VAR.^name;   # Proxy
say $mv.varies.^name;       # Method

<moritz> m: https://gist.github.com/moritz/5cda6371ab3cfec3254e
<camelia> rakudo-moar 0132b6: OUTPUT«Proxy␤Method␤»
<moritz> why does the last line print Method here?
<moritz> and not Int?
<masak> good question.
<masak> does just `$mv.varies` print 6?
<moritz> masak: no, it says <anon>
<masak> sounds wrong to me.
<ShimmerFairy> moritz: Well, it's because you mapped those keys to
Method objects, no?
<masak> ShimmerFairy: isn't that the way you implement a Proxy, though?
<masak> you give FETCH and STORE a callable each. doesn't mean they get exposed.
<ShimmerFairy> masak: I've never seen the method keyword used with it,
I don't think. Just plain closures
<masak> ShimmerFairy: the presence of the `method` keyword there is
practically irrelevant.
<moritz> ShimmerFairy: the 'method' keyword just means they get an invocant
<masak> m: my &c1 = sub ($obj, $x) { say "$obj: $x" }; my &c2 = method
($obj: $x) { say "$obj: $x" }; c1("OH HAI", 42); "OH HAI".&c2(42)
<camelia> rakudo-moar 0132b6: OUTPUT«OH HAI: 42␤OH HAI: 42␤»
<masak> ShimmerFairy: ^
<masak> it's only a matter of intent, not a matter of differing semantics.
<moritz> huh
<moritz> but changing it to a sub instead helps indeed
<moritz> wtf?
<masak> ok, bug
* masak submits rakudobug
<masak> it's probably special-cased where it oughtn't be
<jdv79> i think i ran into that a few months ago and just ignored it
when someone showed me the working one
<masak> let's fix it instead :P

Reply via email to