Skip to content

Instantly share code, notes, and snippets.

@ugexe
Last active November 1, 2015 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugexe/8a83f69fdb81bf989377 to your computer and use it in GitHub Desktop.
Save ugexe/8a83f69fdb81bf989377 to your computer and use it in GitHub Desktop.
rakudo-j bug `my Blob $a = "a".encode; my Blob $b = "b".encode; $a ~= $b; say $a.perl;` + debug output
# https://github.com/rakudo/rakudo/blob/nom/src/core/Buf.pm#L395
multi sub infix:<~>(Blob:D $a, Blob:D $b) {
my $res := ($a.WHAT === $b.WHAT ?? $a !! Buf).new;
say "\$res: {$res.perl}";
say "\$a: {$a.perl}";
say "\$b: {$b.perl}";
my $adc := nqp::decont($a);
say "\$adc: {$adc.perl}";
my $bdc := nqp::decont($b);
say "\$bdc: {$bdc.perl}";
my int $alen = nqp::elems($adc);
say "\$alen: {$alen}";
my int $blen = nqp::elems($bdc);
say "\$blen: {$blen}";
say "nqp::splice({$res.perl}, {$a}, 0, {$alen})";
nqp::splice($res, $a, 0, $alen);
say "res after first splice: {$res.perl}";
nqp::splice($res, $b, $alen, $blen);
say "res after second splice: {$res.perl}";
say '====================';
$res
}
# this shows the error is during the first nqp::splice
nickl@li685-90:~/.rakudobrew/jvm-nom$ perl6 -e 'my Blob $a = "a".encode; my Blob $b = "b".encode; $a ~= $b; say $a.perl;' -------------------
$res: utf8.new()
$a: utf8.new(97)
$b: utf8.new(98)
$adc: utf8.new(97)
$bdc: utf8.new(98)
$alen: 1
$blen: 1
nqp::splice(utf8.new(), a, 0, 1) # `{'a' is really utf8.new(97) but .perl-d}
java.lang.RuntimeException: This type does not support positional operations
in block <unit> at -e:
# I try to emulate the code in the infix sub from Buf.pm, but the error is not reproduced
nickl@li685-90:~/.rakudobrew/jvm-nom$ perl6 -e 'use nqp; my $x := utf8.new(2); my $y := utf8.new(1); my $z := ($x.WHAT === $y.WHAT?? $x !! Buf).new; my $x2 := nqp::decont($x); my $y2 := nqp::decont($y); my int $xlen = nqp::elems($x2); my int $ylen = nqp::elems($y2); say nqp::splice($z, $x, 0, $xlen); say nqp::splice($z, $y, $xlen, $ylen)'
utf8:0x<02>
utf8:0x<02 01>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment