Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix empty return value list producing a stray Nil
Passing an emtpy list returned by a Perl 5 function to another Perl 5
function led to the latter getting an extra argument via the
Nil -> Any -> undef chain.

Fix by replacing return; with return @retvals; (which is empty).
  • Loading branch information
niner committed Jun 23, 2015
1 parent 24600bc commit 75eab84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Inline/Perl5.pm6
Expand Up @@ -434,9 +434,10 @@ method !setup_arguments(@args) {
method !unpack_return_values($av) {
my int32 $av_len = p5_av_top_index($!p5, $av);

my @retvals;
if $av_len == -1 {
p5_sv_refcnt_dec($!p5, $av);
return;
return @retvals; # avoid returning Nil when there are no return values
}

if $av_len == 0 {
Expand All @@ -445,7 +446,6 @@ method !unpack_return_values($av) {
return $retval;
}

my @retvals;
loop (my int32 $i = 0; $i <= $av_len; $i = $i + 1) {
@retvals.push(self.p5_to_p6(p5_av_fetch($!p5, $av, $i)));
}
Expand Down
18 changes: 18 additions & 0 deletions t/invoke.t
Expand Up @@ -16,10 +16,28 @@ $p5.run: q:heredoc/PERL5/;
sub push {
return 'pushed';
}
sub nothing {
return;
}
sub empty_hash {
return {};
}
sub count_args {
return scalar @_;
}
PERL5

my $foo = $p5.invoke('Foo', 'new');

is($foo.push, 'pushed');
my @a = $foo.nothing;
is($foo.count_args($foo.nothing), 1);
is($foo.count_args($foo.empty_hash), 2);

done;

# vim: ft=perl6

0 comments on commit 75eab84

Please sign in to comment.