[perl #128624] Buf initialization error
On Sat, 15 Jul 2017 09:49:10 -0700, jan-olof.hen...@bredband.net wrote: > 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 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 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 at 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. Fixed without a workaround in https://github.com/rakudo/rakudo/commit/29fdb75a3032bd922485d785e9faaec78fc37bb5#diff-260d1fea0c20b1e4f46564df2777fb11 Tests in https://github.com/perl6/roast/commit/32ac651062f3ba06f56aed0d8493b36f07f0dc76
[perl #128624] Buf initialization error
On Sat, 15 Jul 2017 09:49:10 -0700, jan-olof.hen...@bredband.net wrote: > 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 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 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 at 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. Fixed without a workaround in https://github.com/rakudo/rakudo/commit/29fdb75a3032bd922485d785e9faaec78fc37bb5#diff-260d1fea0c20b1e4f46564df2777fb11 Tests in https://github.com/perl6/roast/commit/32ac651062f3ba06f56aed0d8493b36f07f0dc76