On Sun May 01 08:04:06 2016, pesc...@gmail.com wrote:
> On Thu Apr 21 12:34:10 2016, barto...@gmx.de wrote:
> > On Thu Apr 21 11:53:14 2016, barto...@gmx.de wrote:
> > >
> > > $ perl6-j -e 'say < 8+9i >.re'
> > > Attribute '$!re' is not a native num
> > >   in block <unit> at -e line 1
> >
> > Oh, looks like rakudo-j has other problems with the attributes of
> > ComplexStr:
> >
> > $ perl6-j 'say < 8+9i >.im'
> > 8
> 
> The problem here lies somewhere in the generation of the accessors for
> Complex.  We apparently cache the getattr hint for the Attributes in
> Complex and reuse them whenever we call the generated accessor, which
> results in an off-by-one error when we call the same generated
> accessors on a ComplexStr.  Perl 6-level workaround would be to turn
> $.re and $.im in Complex into $!re and $!im and supplying an explicit
> accessor.  Fixing this inside nqp-j probably involves a lot of
> figuring out where and how attribute hints are cached.
> 
> Note that the same problem doesn't occur with IntStr or NumStr because
> they don't have auto-generated accessors, and RatStr gets its
> accessors from the role Rational, which probably gets composed
> differently and thus avoids the issue.  I'm not sure about the details
> there, to be honest.

Here's a golf of the underlying problem:

$ ./perl6-j foo.pl6
Attribute '$!foo' is not a native num
  in block <unit> at foo.pl6 line 13

$ cat foo.pl6
use nqp;
class A { has num $.foo; has num $.baz };
class B { has str $!bar };
class C is A is B {
  method new(Num $a, Str $b) {
    my \SELF = nqp::create(self);
    nqp::bindattr_n(SELF, A, '$!foo', nqp::unbox_n($a));
    nqp::bindattr_n(SELF, A, '$!baz', nqp::unbox_n($a));
    nqp::bindattr_s(SELF, B, '$!bar', nqp::unbox_s($b));
    SELF
  }
};
C.new(5e0, "5").foo.WHAT.say

Reply via email to