Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterating over @(Match) flattens positional captures #935

Closed
p6rt opened this issue Apr 21, 2009 · 4 comments
Closed

Iterating over @(Match) flattens positional captures #935

p6rt opened this issue Apr 21, 2009 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Apr 21, 2009

Migrated from rt.perl.org#64952 (status was 'resolved')

Searchable as RT64952$

@p6rt
Copy link
Author

p6rt commented Apr 21, 2009

From @moritz

Consider this​:

00​:57 <@​moritz_> rakudo​: 'ab' ~~ m/(.)+/; say $0.WHAT; say $1.WHAT
00​:57 < p6eval> rakudo ad7389​: OUTPUT«List␤Failure␤»

A quantified positional captures places a List into $0, and nothing into
$1 - that's correct, in my understanding. But when iterating over @​($/)
it runs the body of the loop twice​:

00​:57 <@​moritz_> rakudo​: .say for @​('ab' ~~ m/(.)+/)
00​:57 < p6eval> rakudo ad7389​: OUTPUT«a␤b␤»

That should be one iteration, where $_ is a List of two Match'es.

I also believe that this accounts for a bug in Match.caps, even though I
changed the tests to think otherwise... I'll try to think a bit more
about it tomorrow, after a good portion of sleep ;-)

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Aug 12, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S05-match/capturing-contexts.t

commit a028ec7cdd599cde941391e8d05699a86608dd76
Author​: kyle <kyle@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Wed Aug 12 21​:07​:20 2009 +0000

  [t/spec] Tests for RT #​64952
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;27972 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S05-match/capturing-contexts.t b/t/spec/S05-match/capturing-contexts.t
index 13e54ef..5de209e 100644
--- a/t/spec/S05-match/capturing-contexts.t
+++ b/t/spec/S05-match/capturing-contexts.t
@@ -2,7 +2,7 @@ use v6;
 
 use Test;
 
-plan 20;
+plan 24;
 
 if !eval('("a" ~~ /a/)') {
   skip_rest "skipped tests - rules support appears to be missing";
@@ -79,4 +79,16 @@ if !eval('("a" ~~ /a/)') {
        '"alpha" exists in Match stored in Hash';
 }
 
+# RT #64952
+{
+    'ab' ~~ /(.)+/;
+    is $/[0][0], 'a', 'match element [0][0] from /(.)+/';
+    is $/[0][1], 'b', 'match element [0][1] from /(.)+/';
+
+    my @match = @( 'ab' ~~ /(.)+/ );
+    #?rakudo 2 todo 'match coerced to array is flattened (RT #64952)'
+    is @match[0][0], 'a', 'match element [0][0] from /(.)+/ coerced';
+    is @match[0][1], 'b', 'match element [0][1] from /(.)+/ coerced';
+}
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Aug 12, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Aug 20, 2010

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Aug 20, 2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant