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

the where clause of parameters is attached to the wrong outer scope on our subs in Rakudo #1555

Closed
p6rt opened this issue Mar 6, 2010 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 6, 2010

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

Searchable as RT73344$

@p6rt
Copy link
Author

p6rt commented Mar 6, 2010

From @masak

<masak> when I write 'our sub foo', the scope of the parameters in the
signature of foo is a global scope rather than a lexical scope, yes?
<TimToady> uh, no
<TimToady> only 'foo' is aliased
<masak> so, how about this?
<masak> rakudo​: my $a = 1; sub foo() { my $a = 2; our sub bar($x where
$a) { say $x } }; bar(1); bar(2)
<p6eval> rakudo 974d9a​: OUTPUT«1␤Constraint type check failed for
parameter '$x' [...]
<TimToady> looks like it's getting the wrong $a to me
* masak submits rakudobug
<TimToady> ($a isn't a parameter though)
<pmichaud> sub foo() { my $a = 2; our sub bar($x where $a) { say $x } }; bar(2);
<pmichaud> rakudo​: sub foo() { my $a = 2; our sub bar($x where $a) {
say $x } }; bar(2);
<p6eval> rakudo 974d9a​: OUTPUT«Symbol '$a' not predeclared in bar [...]
<pmichaud> looks like the where clause is attached to the wrong outer scope
<TimToady> it does at that

@p6rt
Copy link
Author

p6rt commented Oct 11, 2011

From @coke

On Sat Mar 06 05​:23​:08 2010, masak wrote​:

<masak> when I write 'our sub foo', the scope of the parameters in the
signature of foo is a global scope rather than a lexical scope, yes?
<TimToady> uh, no
<TimToady> only 'foo' is aliased
<masak> so, how about this?
<masak> rakudo​: my $a = 1; sub foo() { my $a = 2; our sub bar($x where
$a) { say $x } }; bar(1); bar(2)
<p6eval> rakudo 974d9a​: OUTPUT«1␤Constraint type check failed for
parameter '$x' [...]
<TimToady> looks like it's getting the wrong $a to me
* masak submits rakudobug
<TimToady> ($a isn't a parameter though)
<pmichaud> sub foo() { my $a = 2; our sub bar($x where $a) { say $x }
}; bar(2);
<pmichaud> rakudo​: sub foo() { my $a = 2; our sub bar($x where $a) {
say $x } }; bar(2);
<p6eval> rakudo 974d9a​: OUTPUT«Symbol '$a' not predeclared in bar
[...]
<pmichaud> looks like the where clause is attached to the wrong outer
scope
<TimToady> it does at that

Current behavior​:

20​:20 < [Coke]> rakudo​: my $a = 1; sub foo() { my $a = 2; our sub bar($x where
  $a) { say $x } }; bar(1); bar(2)
20​:20 <+p6eval> rakudo 38907e​: OUTPUT«Could not find sub &bar␤ in block <anon>
  at /tmp/XCB2X1q5A9​:1␤ in <anon> at /tmp/XCB2X1q5A9​:1␤»
20​:20 < [Coke]> rakudo​: sub foo() { my $a = 2; our sub bar($x where $a) { say
  $x } }; bar(2);
20​:20 <+p6eval> rakudo 38907e​: OUTPUT«Could not find sub &bar␤ in block <anon>
  at /tmp/hSS1YJsEDY​:1␤ in <anon> at /tmp/hSS1YJsEDY​:1␤»

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Oct 11, 2011

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

@p6rt
Copy link
Author

p6rt commented Oct 11, 2011

From @masak

On Mon Oct 10 17​:20​:53 2011, coke wrote​:

On Sat Mar 06 05​:23​:08 2010, masak wrote​:

<masak> when I write 'our sub foo', the scope of the parameters in
the
signature of foo is a global scope rather than a lexical scope, yes?
<TimToady> uh, no
<TimToady> only 'foo' is aliased
<masak> so, how about this?
<masak> rakudo​: my $a = 1; sub foo() { my $a = 2; our sub bar($x
where
$a) { say $x } }; bar(1); bar(2)
<p6eval> rakudo 974d9a​: OUTPUT«1␤Constraint type check failed for
parameter '$x' [...]
<TimToady> looks like it's getting the wrong $a to me
* masak submits rakudobug
<TimToady> ($a isn't a parameter though)
<pmichaud> sub foo() { my $a = 2; our sub bar($x where $a) { say $x
}
}; bar(2);
<pmichaud> rakudo​: sub foo() { my $a = 2; our sub bar($x where $a) {
say $x } }; bar(2);
<p6eval> rakudo 974d9a​: OUTPUT«Symbol '$a' not predeclared in bar
[...]
<pmichaud> looks like the where clause is attached to the wrong
outer
scope
<TimToady> it does at that

Current behavior​:

20​:20 < [Coke]> rakudo​: my $a = 1; sub foo() { my $a = 2; our sub
bar($x where
$a) { say $x } }; bar(1); bar(2)
20​:20 <+p6eval> rakudo 38907e​: OUTPUT«Could not find sub &bar␤ in
block <anon>
at /tmp/XCB2X1q5A9​:1␤ in <anon> at
/tmp/XCB2X1q5A9​:1␤»
20​:20 < [Coke]> rakudo​: sub foo() { my $a = 2; our sub bar($x where
$a) { say
$x } }; bar(2);
20​:20 <+p6eval> rakudo 38907e​: OUTPUT«Could not find sub &bar␤ in
block <anon>
at /tmp/hSS1YJsEDY​:1␤ in <anon> at
/tmp/hSS1YJsEDY​:1␤»

<masak> https://rt-archive.perl.org/perl6/Ticket/Display.html?id=73344 needs
reformulating because 'our' subs don't work that way anymore.
<masak> not sure the same behaviour can be had with the new 'our' sub
semantics.
<moritz> masak​: just return sub bar from sub foo
<masak> moritz++​: I'll try that
<masak> rakudo​: my $a = 1; sub foo { my $a = 2; sub bar($x where $a) {
say "called with $x" }; &bar }; foo()(2); foo()(1)
<p6eval> rakudo 38907e​: OUTPUT«called with 2␤Constraint type check
failed for parameter '$x' [...]
<moritz> rakudo​: my $a = 1; sub foo() { my $a = 2; sub bar($x where $a)
{ say $x } }; my &bar := foo; bar(1)
<p6eval> rakudo 38907e​: OUTPUT«Constraint type check failed for
parameter '$x' [...]
<masak> all indications point to it working nowadays.
* masak adds that to the ticket

Can be closed module needstests.

@p6rt
Copy link
Author

p6rt commented Oct 11, 2011

From @moritz

now tested in S02-types/subset.t

@p6rt
Copy link
Author

p6rt commented Oct 11, 2011

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

@p6rt p6rt closed this as completed Oct 11, 2011
@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