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

@_ is writeable in subroutines without explicit signature in Rakudo; shouldn't be #1432

Closed
p6rt opened this issue Dec 8, 2009 · 6 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 8, 2009

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

Searchable as RT71112$

@p6rt
Copy link
Author

p6rt commented Dec 8, 2009

From @masak

<masak> rakudo​: sub foo { @​_[0] = "bah" }; my $a = "!"; foo($a); say $a
<p6eval> rakudo 7ef386​: !␤
<TimToady> i'd've expected it to blow up
* masak submits rakudobug
<masak> TimToady​: so in the default signature, @​_ isn't writeable?
<TimToady> no, it's different from P5 in that
<masak> ok.
<TimToady> but most P5 programs aren't modifying their parameters
<TimToady> and we didn't want to pay the might-be-lvalue penalty anymore
<TimToady> that was decided in about 2003 or so
<masak> nod.

@p6rt
Copy link
Author

p6rt commented Jan 11, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S06-signature/unspecified.t

commit feadec2cec905db9b25b782725463e449c7a0006
Author​: kyle <kyle@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Mon Jan 11 21​:15​:44 2010 +0000

  [t/spec] Test for RT 71112​: Cannot assign to readonly variable.
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;29524 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S06-signature/unspecified.t b/t/spec/S06-signature/unspecified.t
index 6bf0ed9..d9133f6 100644
--- a/t/spec/S06-signature/unspecified.t
+++ b/t/spec/S06-signature/unspecified.t
@@ -1,7 +1,7 @@
 use v6;
 use Test;
 
-plan 15;
+plan *;
 
 # L<S06/Perl5ish subroutine declarations/You can declare a sub without
 # parameter list>
@@ -41,4 +41,15 @@ is both( 'x', :delta<echo>, 'foxtrot' ), 'foxtrotecho',
 is both(), '',
    'sub using both named and position params works with no params';
 
+# RT 71112
+{
+    sub rt71112 { @_[0] = 'bug' }
+    my $tender = 'sanity';
+    #?rakudo todo 'RT 71112: Cannot assign to readonly variable.'
+    dies_ok { rt71112( $tender ) }, 'Sub that tries to modify @_ dies';
+    is $tender, 'sanity', 'The variable passed is unchanged.';
+}
+
+done_testing;
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Jan 11, 2010

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

@p6rt
Copy link
Author

p6rt commented Sep 11, 2011

From @bbkr

NOM​: still broken (allows to modify @​_)

bbkr​:nom bbkr$ ./perl6 -e 'sub foo { @​_[0] = "bah" }; my $a = "!";
foo($a); say $a'
!

@p6rt
Copy link
Author

p6rt commented Nov 12, 2015

From @jnthn

On Mon Dec 07 21​:36​:46 2009, masak wrote​:

<masak> rakudo​: sub foo { @​_[0] = "bah" }; my $a = "!"; foo($a); say $a
<p6eval> rakudo 7ef386​: !␤
<TimToady> i'd've expected it to blow up
* masak submits rakudobug
<masak> TimToady​: so in the default signature, @​_ isn't writeable?
<TimToady> no, it's different from P5 in that
<masak> ok.
<TimToady> but most P5 programs aren't modifying their parameters
<TimToady> and we didn't want to pay the might-be-lvalue penalty anymore
<TimToady> that was decided in about 2003 or so
<masak> nod.

The ruling is that, since *@​_ would have "is copy" semantics, so the default @​_ should. Reference​:

http://irclog.perlgeek.de/perl6/2015-11-12#i_11527317

Codified the ruling in the spectests in S06-signature/unspecified.t.

/jnthn

@p6rt p6rt closed this as completed Nov 12, 2015
@p6rt
Copy link
Author

p6rt commented Nov 12, 2015

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

@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