@@ -851,6 +851,7 @@ class NQPCursor does NQPCursorRole {
851
851
# For captures with lists, initialize the lists.
852
852
my % caplist := $ NO_CAPS ;
853
853
my $ rxsub := nqp ::getattr(self , NQPCursor, ' $!regexsub' );
854
+ my int $ sawcaps := 0 ;
854
855
if ! nqp ::isnull($ rxsub ) && nqp :: defined ($ rxsub ) {
855
856
% caplist := nqp :: can ($ rxsub , ' CAPS' ) ?? $ rxsub . CAPS() !! nqp ::null();
856
857
if ! nqp ::isnull(% caplist ) && nqp ::istrue(% caplist ) {
@@ -864,22 +865,26 @@ class NQPCursor does NQPCursorRole {
864
865
nqp ::defor($ list , $ list := nqp ::list()),
865
866
$ name , nqp ::list())
866
867
!! nqp ::bindkey($ hash , $ name , nqp ::list());
868
+ $ sawcaps := 1 ;
869
+ }
870
+ elsif nqp ::iterval($ curcap ) >= 1 {
871
+ $ sawcaps := 1 ;
867
872
}
868
873
}
869
874
}
870
875
}
871
876
872
877
# Walk the Cursor stack and populate the Cursor.
873
878
my $ cs := nqp ::getattr(self , NQPCursor, ' $!cstack' );
874
- if ! nqp ::isnull($ cs ) && nqp ::istrue($ cs ) {
879
+ if $ sawcaps && ! nqp ::isnull($ cs ) && nqp ::istrue($ cs ) {
875
880
my int $ cselems := nqp :: elems ($ cs );
876
881
my int $ csi ;
877
882
while $ csi < $ cselems {
878
883
my $ subcur := nqp ::atpos($ cs , $ csi );
879
- my $ submatch := $ subcur . MATCH;
880
884
my $ name := nqp ::getattr($ subcur , $ ? CLASS , ' $!name' );
881
- if ! nqp ::isnull($ name ) && nqp :: defined ($ name ) {
882
- if $ name ne ' ' && nqp ::ordat($ name , 0 ) == 36 && ($ name eq ' $!from' || $ name eq ' $!to' ) {
885
+ if ! nqp ::isnull($ name ) && nqp :: defined ($ name ) && $ name ne ' ' {
886
+ my $ submatch := $ subcur . MATCH();
887
+ if nqp ::ordat($ name , 0 ) == 36 && ($ name eq ' $!from' || $ name eq ' $!to' ) {
883
888
nqp ::bindattr_i($ match , NQPMatch, $ name , $ submatch . from );
884
889
}
885
890
elsif nqp :: index ($ name , ' =' ) < 0 {
0 commit comments