Navigation Menu

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

For loops and junctions misbehave in Rakudo #745

Closed
p6rt opened this issue Mar 7, 2009 · 7 comments
Closed

For loops and junctions misbehave in Rakudo #745

p6rt opened this issue Mar 7, 2009 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Mar 7, 2009

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

Searchable as RT63686$

@p6rt
Copy link
Author

p6rt commented Mar 7, 2009

From @moritz

This works​:

17​:58 <@​moritz_> rakudo​: my %h = ( a => any(3, 4) ); say %h<a>.WHAT;
17​:58 < p6eval> rakudo f6cdf9​: OUTPUT«Junction␤»

This doesn't​:
17​:55 <@​moritz_> rakudo​: my %h = ( a => any(3, 4) ); for %h.kv -> $k, $v
{ say "$k​: {$v.WHAT}" };
17​:55 < p6eval> rakudo f6cdf9​: OUTPUT«a​: Int␤a​: Int␤No exception handler
and no message␤current instr.​: 'return' pc 16018
  (src/builtins/control.pir​:39)␤»

(I think it's correct that it autothreads over $k because it's not
declared as Object, but it shouldn't throw an exception anywhere).

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Mar 8, 2009

From @masak

<masak> rakudo​: for any(1,2) -> $x {}
<p6eval> rakudo ed4cd1​: OUTPUT«No exception handler and no message [...]
<masak> bug?
<bacek> masak​: actually no.
<masak> why not?
<bacek> rakudo​: try { for any(1,2) -> $x {}; }
<p6eval> rakudo ed4cd1​: RESULT«Null PMC access in find_method() [...]
* masak submits rakudobug
<bacek> rakudo​: sub foo { for any(1,2) -> $x {}; }; foo
<p6eval> rakudo ed4cd1​: RESULT«any(undef, undef)»
<masak> there's a return in there somewhere.
<bacek> in REPL

I see two bugs above. First, the cryptic equivalent of Perl 5's "Can't
return outside a subroutine" is thrown for no good reason when
for-looping over a junction. Second, a Null PMC access is caused by
doing the same inside a try block.

@p6rt
Copy link
Author

p6rt commented Mar 13, 2009

From @jnthn

On Sat Mar 07 09​:04​:51 2009, moritz wrote​:

This works​:

17​:58 <@​moritz_> rakudo​: my %h = ( a => any(3, 4) ); say %h<a>.WHAT;
17​:58 < p6eval> rakudo f6cdf9​: OUTPUT«Junction␤»

This doesn't​:
17​:55 <@​moritz_> rakudo​: my %h = ( a => any(3, 4) ); for %h.kv -> $k, $v
{ say "$k​: {$v.WHAT}" };
17​:55 < p6eval> rakudo f6cdf9​: OUTPUT«a​: Int␤a​: Int␤No exception handler
and no message␤current instr.​: 'return' pc 16018
(src/builtins/control.pir​:39)␤»

(I think it's correct that it autothreads over $k because it's not
declared as Object, but it shouldn't throw an exception anywhere).

Ah yes, I'd forgotten that we can bind sigs on a block that ain't a
routine also. The answer is that we need to leave the caller instead of
doing a return.

Jonathan

@p6rt
Copy link
Author

p6rt commented Mar 13, 2009

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

@p6rt
Copy link
Author

p6rt commented Jul 24, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S03-junctions/misc.t

commit dcde0ac24640877f0b8ff37a22ffef553283bbad
Author​: kyle <kyle@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Fri Jul 24 19​:38​:28 2009 +0000

  [t/spec] (perhaps incomplete) test for RT #​63686
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;27709 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S03-junctions/misc.t b/t/spec/S03-junctions/misc.t
index 1b9515f..d02666f 100644
--- a/t/spec/S03-junctions/misc.t
+++ b/t/spec/S03-junctions/misc.t
@@ -2,7 +2,7 @@ use v6;
 
 use Test;
 
-plan 95;
+plan 97;
 
 =begin pod
 
@@ -408,6 +408,14 @@ sub junction_diff(Object $this, Object $that) {
   is_deeply(junction_diff(1|2, 1|2|3), ["3 is missing from this"], 'Value is missing from left side');
 }
 
+# RT #63686
+{
+    lives_ok { try { for any(1,2) -> $x {}; } },
+             'for loop over junction in try block';
 
-
-
+    sub rt63686 {
+        for any(1,2) -> $x {};
+        return 'happiness';
+    }
+    is rt63686(), 'happiness', 'for loop over junction in sub';
+}

@p6rt
Copy link
Author

p6rt commented Mar 9, 2010

From @moritz

As per current spec rakudo sets the default type of block parameters to
Mu, thus no autothreading happens anymore.

@p6rt
Copy link
Author

p6rt commented Mar 9, 2010

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

@p6rt p6rt closed this as completed Mar 9, 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