The-attached patch seems to fix it; and honestly I'm more than a little surprised how simple it is.
--
Paul Evans
=== modified file 'lib/Future/AsyncAwait.xs'
--- lib/Future/AsyncAwait.xs 2019-04-26 21:32:44 +0000
+++ lib/Future/AsyncAwait.xs 2019-06-04 15:24:45 +0000
@@ -147,6 +147,8 @@
U32 padlen;
SV **padslots;
+
+ PMOP *curpm; /* value of PL_curpm at suspend time */
} SuspendedState;
#ifdef DEBUG
@@ -1065,6 +1067,11 @@
}
}
+ if(PL_curpm)
+ state->curpm = PL_curpm;
+ else
+ state->curpm = NULL;
+
dounwind(cxix);
}
@@ -1339,6 +1346,9 @@
Safefree(frame);
}
state->frames = NULL;
+
+ if(state->curpm)
+ PL_curpm = state->curpm;
}
/*
=== modified file 't/13regexp.t'
--- t/13regexp.t 2019-04-26 13:39:17 +0000
+++ t/13regexp.t 2019-06-04 15:24:45 +0000
@@ -26,4 +26,21 @@
is( scalar $fret->get, 3, 'chunks' );
}
+# await over regexp (RT129321)
+{
+ my $f1 = Future->new;
+ my $fret = (async sub {
+ my $string = "Hello, world";
+ $string =~ m/^(.*),/;
+
+ await $f1;
+
+ return $1, $-[1], $+[1];
+ })->();
+
+ $f1->done;
+ is_deeply( [ $fret->get ], [ "Hello", 0, 5 ],
+ 'await restores regexp context' );
+}
+
done_testing;