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

Bug returning objects directly from called methods using some form of named arguments #4681

Open
p6rt opened this issue Oct 26, 2015 · 1 comment

Comments

@p6rt
Copy link

p6rt commented Oct 26, 2015

Migrated from rt.perl.org#126462 (status was 'new')

Searchable as RT126462$

@p6rt
Copy link
Author

p6rt commented Oct 26, 2015

From @MARTIMM

Two samples of code for which the problem is closely related

The first problem;

  return MongoDB​::Cursor.new(
  collection => self,
  OP_REPLY => $OP_REPLY,
  criteria => %@​criteria
  );

Generates the error; 'Default constructor for 'MongoDB​::Cursor' only
takes named arguments'

The second problem;

  return self.find-and-modify(
  $criteria, $projection, :$remove, :$update, :$sort,
  :$new, :$upsert
  );

Generates​: 'Too many positionals passed; expected 1 to 3 arguments but
got 8'

The different errors are caused by the order of testing steps done by
perl6. The named arguments are converted to or seen as positionals in
some way when it is used together with the return statement.

To make it work I had to resort to the following.

  my $c = MongoDB​::Cursor.new(
  collection => self,
  OP_REPLY => $OP_REPLY,
  criteria => %@​criteria
  );

  return $c;

and for the second the same way

  my $h = self.find-and-modify(
  $criteria, $projection, :$remove, :$update, :$sort,
  :$new, :$upsert
  );

  return $h;

perl6 version 2015.09-346-g0251b52 built on MoarVM version
2015.09-74-gedc44b5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant