On Fri, 15 Jul 2016 02:45:51 -0700, mt1...@gmail.com wrote: > Hi, > > Old code gives now error in Rakudo version 2016.06-234-g0189851 built on > MoarVM version 2016.06-9-g8fc21d5. > > Code is > > sub encode-int32 ( Int:D $i --> Buf ) is export { > my int $ni = $i; > return Buf.new( $ni +& 0xFF, ($ni +> 0x08) +& 0xFF, > ($ni +> 0x10) +& 0xFF, ($ni +> 0x18) +& 0xFF > ); > } > > Fails at ' return Buf.new( $ni +& 0xFF, ....' when argument $i=5 with error > > > Type check failed in initializing element #0 to Buf; expected uint8 but > got Int (5) > in any at gen/moar/m-Metamodel.nqp line 1736 > in sub encode-int32 at > /home/marcel/Languages/Perl6/Projects/BSON/lib/BSON/Document.pm6 > (BSON::Document) line 948 > in method encode at > /home/marcel/Languages/Perl6/Projects/BSON/lib/BSON/Document.pm6 > (BSON::Document) line 696 > in block <unit> at t/300-document.t line 10 > > Actually thrown at: > in any at gen/moar/m-Metamodel.nqp line 3055 > in any at gen/moar/m-Metamodel.nqp line 1736 > in sub encode-int32 at > /home/marcel/Languages/Perl6/Projects/BSON/lib/BSON/Document.pm6 > (BSON::Document) line 948 > in method encode at > /home/marcel/Languages/Perl6/Projects/BSON/lib/BSON/Document.pm6 > (BSON::Document) line 696 > in block <unit> at t/300-document.t line 10 > > > In REPL golfed down to > > > my int $i = 5 > > Buf.new($i +& 0xFF) > Type check failed in initializing element #0 to Buf; expected uint8 but > got Int (5) > in any at gen/moar/m-Metamodel.nqp line 1736 > in block <unit> at <unknown file> line 1 > > > Neither $i or 0xFF on its own will trigger this error so its the > combination caused by the +& operator. Also 'Buf.new(|($i +& 0xFF))' > helps but is rather cumbersome for the programmer as well as the compiler! > > greetings, > > Marcel >
The above works since https://github.com/rakudo/rakudo/commit/242baf256a210f1cb643cb6324916dbc76184c9f. Note however that the fix is marked as 'temporary', i.e. a workaround.