# New Ticket Created by  mt1957 
# Please include the string:  [perl #126462]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=126462 >


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


Reply via email to