Skip Menu |
 

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

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

People
Owner: Nobody in particular
Requestors: ilmari [...] ilmari.org
Cc:
AdminCc:

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



Subject: String eval not handled (and misleading error message)
Date: Fri, 10 Aug 2018 11:43:48 +0100
To: bug-Future-AsyncAwait [...] rt.cpan.org
From: ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker)
Download (untitled) / with headers
text/plain 618b
Calling await inside a string eval doesn't work, and complains that it's not inside an 'async sub', even if the string eval is: $ perl -MFuture::AsyncAwait -wE 'async sub foo { 42 }' \ -e 'async sub bar { eval q{ await foo } or die $@ }' \ -e 'say bar->get' Cannot 'await' outside of an 'async sub' at (eval 8) line 1. - ilmari -- - Twitter seems more influential [than blogs] in the 'gets reported in the mainstream press' sense at least. - Matt McLeod - That'd be because the content of a tweet is easier to condense down to a mainstream media article. - Calle Dybedahl
Download (untitled) / with headers
text/plain 194b
The attached patch makes a better error message $ perl -Mblib -MFuture::AsyncAwait -e 'eval "await $_[0]" or die $@' await is not allowed inside string eval at (eval 8) line 1. -- Paul Evans
Subject: rt126035.patch
Download rt126035.patch
text/x-diff 1.1k
=== modified file 'lib/Future/AsyncAwait.xs' --- lib/Future/AsyncAwait.xs 2019-06-04 19:27:45 +0000 +++ lib/Future/AsyncAwait.xs 2019-06-04 19:43:54 +0000 @@ -1973,7 +1973,9 @@ SV **asynccvrefp = hv_fetchs(GvHV(PL_hintgv), "Future::AsyncAwait/PL_compcv", 0); if(!asynccvrefp || !*asynccvrefp || SvRV(*asynccvrefp) != (SV *)PL_compcv) - croak("Cannot 'await' outside of an 'async sub'"); + croak(CvEVAL(PL_compcv) ? + "await is not allowed inside string eval" : + "Cannot 'await' outside of an 'async sub'"); lex_read_space(0); === modified file 't/30stringeval.t' --- t/30stringeval.t 2019-01-05 19:28:59 +0000 +++ t/30stringeval.t 2019-06-04 19:43:54 +0000 @@ -26,6 +26,20 @@ }, 'async/await from within string eval'; } +# await at string-eval level should be forbidden (RT126035) +{ + my $ok; + my $e; + + (async sub { + $ok = !eval q{await $_[0]}; + $e = $@; + })->(); + + ok( $ok, 'await in string eval fails to compile' ); + $ok and like( $e, qr/^await is not allowed inside string eval /, '' ); +} + is( Future::AsyncAwait::__cxstack_ix, $orig_cxstack_ix, 'cxstack_ix did not grow during the test' );
Released in 0.27 -- Paul Evans


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.