Skip Menu |

This queue is for tickets about the Future-AsyncAwait CPAN distribution.

Report information
The Basics
Id: 129836
Status: resolved
Priority: 0/
Queue: Future-AsyncAwait

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.27
Fixed in: 0.28



Subject: "Cannot await outside of async sub" from anon inside named
use strict; use warnings; use Future::AsyncAwait; async sub outer { my $inner = async sub { return 'inner'; }; return await $inner->(); } warn outer->get(); Fails: Cannot 'await' outside of an 'async sub' at rt.pl line 11. -- Paul Evans
Adding some debug prints: Begun parsing async sub outer with PL_compcv=0x556b3fb71d00 Begun parsing async sub __ANON__ with PL_compcv=0x556b4002c3a8 asynccvrefp=0x556b40217cb0 SvRV(*refp)=0x556b4002c3a8 PL_compcv=0x556b3fb71d00 Cannot 'await' outside of an 'async sub' at t/90rt129836.t line 15. It appears to be that the value in the hints hash isn't localised properly and doesn't get restored after the inner one is done, so when parsing `await` in the outer we still see the inner value in the hash. -- Paul Evans
Needed a SAVEHINTS(). Patch attached -- Paul Evans
Subject: rt129836.patch
=== modified file 'lib/Future/AsyncAwait.xs' --- lib/Future/AsyncAwait.xs 2019-06-04 19:43:54 +0000 +++ lib/Future/AsyncAwait.xs 2019-06-17 15:55:08 +0000 @@ -1923,7 +1923,10 @@ /* Save the identity of the currently-compiling sub so that * await_keyword_plugin() can check */ - hv_stores(GvHV(PL_hintgv), "Future::AsyncAwait/PL_compcv", newRV((SV *)PL_compcv)); + PL_hints |= HINT_LOCALIZE_HH; + SAVEHINTS(); + + hv_stores(GvHV(PL_hintgv), "Future::AsyncAwait/PL_compcv", newSVuv(PTR2UV(PL_compcv))); I32 save_ix = block_start(TRUE); @@ -1970,9 +1973,8 @@ static int await_keyword_plugin(pTHX_ OP **op_ptr) { - SV **asynccvrefp = hv_fetchs(GvHV(PL_hintgv), "Future::AsyncAwait/PL_compcv", 0); - if(!asynccvrefp || !*asynccvrefp || - SvRV(*asynccvrefp) != (SV *)PL_compcv) + SV **asynccvp = hv_fetchs(GvHV(PL_hintgv), "Future::AsyncAwait/PL_compcv", 0); + if(!asynccvp || SvUV(*asynccvp) != PTR2UV(PL_compcv)) croak(CvEVAL(PL_compcv) ? "await is not allowed inside string eval" : "Cannot 'await' outside of an 'async sub'"); === added file 't/90rt129836.t' --- t/90rt129836.t 1970-01-01 00:00:00 +0000 +++ t/90rt129836.t 2019-06-17 09:51:20 +0000 @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; + +use Future::AsyncAwait; + +async sub outer { + my $inner = async sub { + return "inner"; + }; + + return await $inner->(); +} + +is( outer()->get, "inner", 'result of anon inside named' ); + +done_testing;
Was fixed in 0.28 -- Paul Evans