Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buf initialization error #5452

Closed
p6rt opened this issue Jul 15, 2016 · 5 comments
Closed

Buf initialization error #5452

p6rt opened this issue Jul 15, 2016 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Jul 15, 2016

Migrated from rt.perl.org#128624 (status was 'resolved')

Searchable as RT128624$

@p6rt
Copy link
Author

p6rt commented Jul 15, 2016

From @MARTIMM

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

@p6rt
Copy link
Author

p6rt commented Jul 15, 2017

From @dogbert17

On Fri, 15 Jul 2016 02​:45​:51 -0700, mt1957@​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 rakudo/rakudo@242baf2.
Note however that the fix is marked as 'temporary', i.e. a workaround.

@p6rt
Copy link
Author

p6rt commented Jul 15, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 6, 2018

From @zoffixznet

On Sat, 15 Jul 2017 09​:49​:10 -0700, jan-olof.hendig@​bredband.net wrote​:

On Fri, 15 Jul 2016 02​:45​:51 -0700, mt1957@​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
rakudo/rakudo@242baf2.
Note however that the fix is marked as 'temporary', i.e. a workaround.

Fixed without a workaround in rakudo/rakudo@29fdb75#diff-260d1fea0c20b1e4f46564df2777fb11
Tests in Raku/roast@32ac651

@p6rt
Copy link
Author

p6rt commented Apr 6, 2018

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Apr 6, 2018
@p6rt p6rt added the testneeded label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant