summaryrefslogtreecommitdiff
path: root/inline.h
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2020-08-25 13:15:25 +0100
committerDavid Mitchell <davem@iabyn.com>2020-08-25 13:29:48 +0100
commit390fe0c0d09aadc66f644e9eee4aa1245221188c (patch)
tree31b7f0ee843a4d231e2044af8601ba6313f46b46 /inline.h
parent2385767d7185ad354e927939655b3f824fe82f57 (diff)
downloadperl-390fe0c0d09aadc66f644e9eee4aa1245221188c.tar.gz
sort { return foo() } ...
GH #18081 A sub call via return in a sort block was called in void rather than scalar context, causing the comparison result to be discarded. This because when a sort block is called it is not a real function call, even though a sort block can be returned from. Instead, a CXt_NULL is pushed on the context stack. Because this isn't a sub-ish context type (unlike CXt_SUB, CXt_EVAL etc) there is no 'caller sub' on the context stack to be found to retrieve the caller's context (i.e. cx->cx_gimme). This commit fixes it by special-casing Perl_gimme_V(). Ideally at some future point, a new context type, CXt_SORT, should be added. This would be used instead of CXt_NULL when a sort BLOCK is called. Like other sub-ish context types, it would have an old_cxsubix field and PL_curstackinfo->si_cxsubix would point to it. This would eliminate needing special-case handling in places like Perl_gimme_V().
Diffstat (limited to 'inline.h')
-rw-r--r--inline.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/inline.h b/inline.h
index a8240efb9c..6fbd5abfea 100644
--- a/inline.h
+++ b/inline.h
@@ -2086,7 +2086,7 @@ Perl_gimme_V(pTHX)
return gimme;
cxix = PL_curstackinfo->si_cxsubix;
if (cxix < 0)
- return G_VOID;
+ return PL_curstackinfo->si_type == PERLSI_SORT ? G_SCALAR: G_VOID;
assert(cxstack[cxix].blk_gimme & G_WANT);
return (cxstack[cxix].blk_gimme & G_WANT);
}