Here's another interesting one. Take this class:
class Path {
has cairo_path_t $.path handles <data num_data>;
has $!index = 0;
submethod BUILD (:$!path) { }
method AT-POS(|) {
die 'Sorry! Cairo::Path is an iterated list, not an array.'
}
method get_data(Int $i) {
#nativecast( CArray[cairo_path_data_t], $!path.data[$i] );
nativecast( CArray[Pointer], $!path.data[$i] );
}
method iterator {
my $oc = self;
my $path = $!path;
say 'Iterator';
class :: does Iterator {
has $.index is rw = 0;
method pull-one {
say 'Pulling';
my $r := $path.num_data > $.index ??
$oc.get_data($.index) !! IterationEnd;
$.index += $r.header.length;
say "Iterator: { $r.^name }";
$r;
}
}.new;
}
method new (cairo_path_t $path) {
self.bless(:$path);
}
method destroy {
$!path.destroy;
}
}
So you would expect that this:
my $p = $path.iterator.pull-one;
Would pull the first element from $!path. It doesn't. Instead, I get the following:
Iterator
Pulling
Unknown element type in CArray
in method <anon> at /home/cbwood/Projects/rakudobrew/moar-master/install/share/perl6/sources/8660F65A7B3492675BB3B2058DB30E411A4C4E54 (NativeCall::Types) line 163
in method get_data at /home/cbwood/Projects/p6-Pango/../cairo-p6/lib/Cairo.pm6 (Cairo) line 1565
in method pull-one at /home/cbwood/Projects/p6-Pango/../cairo-p6/lib/Cairo.pm6 (Cairo) line 1580
in sub fancy_cairo_stroke at t/02-twisted.t line 15
in sub draw_dream at t/02-twisted.t line 276
in sub MAIN at t/02-twisted.t line 295
in block <unit> at t/02-twisted.t line 290
Now I know for a fact that CArray[Pointer] is valid, so why is this error popping up?