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

endless loop when calling nextsame in two multis differing only by constraints #3718

Closed
p6rt opened this issue Mar 5, 2015 · 6 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 5, 2015

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

Searchable as RT123989$

@p6rt
Copy link
Author

p6rt commented Mar 5, 2015

From @niner

multi foo(Int $foo where * > 0) {
  say ">0";
  nextsame;
}
multi foo(Int $foo where * < 10) {
  say "<10";
  nextsame;
}
multi foo($foo) {
  say "generic";
}
foo(1);

prints​:

0
<10
<10
<10
<10
...
and loops endlessly

@p6rt
Copy link
Author

p6rt commented Apr 1, 2015

From @niner

0
ctx​: 0x5001b60, disp_lex​: 0x5071450
maybe_dispatcher​: 0x1eeaa30
ctx​: 0x5002460, disp_lex​: 0x51766a8
maybe_dispatcher​: 0x2795540
no concrete dispatcher​: 0x2795540
<10
ctx​: 0x5001260, disp_lex​: 0x5071480
maybe_dispatcher​: 0x1eeaa30
ctx​: 0x5001380, disp_lex​: 0x51765c8
maybe_dispatcher​: 0x2795540
no concrete dispatcher​: 0x2795540
<10
ctx​: 0x5000cc0, disp_lex​: 0x5071468
maybe_dispatcher​: 0x1eeaa30
ctx​: 0x5000ba0, disp_lex​: 0x5176520
maybe_dispatcher​: 0x2795540
no concrete dispatcher​: 0x2795540

ctx and therefore disp_lex is different on every iteration. So the vivified dispatcher is stored in the $*DISPATCHER lexical, but every time it's a different lexical. This is why we get a new dispatcher every time that does not share state with the old one and thus tries the same method again that already was invoked.

@p6rt
Copy link
Author

p6rt commented Apr 4, 2015

From @niner

The lambda in the multi method's signature like all blocks does a takedispatcher, thus eating the cur_dispatcher that was meant for the method's body.

@p6rt
Copy link
Author

p6rt commented Jan 3, 2017

From @jnthn

On Thu, 05 Mar 2015 02​:12​:21 -0800, nine@​detonation.org wrote​:

multi foo(Int $foo where * > 0) {
say ">0";
nextsame;
}
multi foo(Int $foo where * < 10) {
say "<10";
nextsame;
}
multi foo($foo) {
say "generic";
}
foo(1);

prints​:

0
<10
<10
<10
<10
...
and loops endlessly

Fixed and test added to S12-methods/defer-next.t.

/jnthn

@p6rt
Copy link
Author

p6rt commented Jan 3, 2017

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

@p6rt
Copy link
Author

p6rt commented Jan 3, 2017

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

@p6rt p6rt closed this as completed Jan 3, 2017
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant