Yes, this is because classes / roles are not proper closures. And yes, I’ve been bitten by this as well.
To me, making them proper closures, feels like the correct solution to me. But I’ll settle for a warning / exceptione :-) > On 9 Mar 2017, at 16:35, Sam S. (via RT) <[email protected]> wrote: > > # New Ticket Created by Sam S. > # Please include the string: [perl #130965] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=130965 > > > > sub a ($a) { > return True but role { > method foo { $a } > } > } > > my $x = a 42; > say $x.foo; # 42 > > my $y = a "Hello"; > say $y.foo; # Hello > say $x.foo; # Hello > > I have a suspicion that this is not a bug but rather a consequence of > classes/roles not being proper closures. > > But the current behavior is rather LTA in cases like this. > Could this possibly be made to emit a warning?
