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 rw' allows constant arguments to change in Rakudo #1060

Closed
p6rt opened this issue Jun 15, 2009 · 5 comments
Closed

'is rw' allows constant arguments to change in Rakudo #1060

p6rt opened this issue Jun 15, 2009 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 15, 2009

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

Searchable as RT66588$

@p6rt
Copy link
Author

p6rt commented Jun 15, 2009

From @masak

Submitting the below message as a bug per John's request.

---------- Forwarded message ----------
From​: John M. Dlugosz <2nb81lz02@​sneakemail.com>
Date​: Mon, Jun 15, 2009 at 4​:43 AM
Subject​: Re​: Why pass by reference?
To​: perl6-language@​perl.org

[...]

No, "is rw" does not like immutables.  It will cause autovivification
to take place, but will not accept something that is not an lvalue
such as 1 or "Hello" literals.  This was just doubled-checked with
S06, S09, and discussion with Larry in #perl6.  If Ra

  <ruoso>    rakudo​: sub foo($a is rw) { $a += 1; say $a }; foo(1);
  <p6eval>   rakudo 77f9d7​: OUTPUT«2␤»

that directly contradicts S06, which states "Otherwise the signature
fails to bind, and this candidate routine cannot be considered for
servicing this particular call."  Doing otherwise affects the
semantics of MMD for allowing overloading based on whether the
parameter is an lvalue or not.

Somebody who works with rakudo could submit a bug, if it's not in there already?

@p6rt
Copy link
Author

p6rt commented Nov 13, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in at least one of these files​: t/spec/S02-magicals/dollar_bang.t, t/spec/S06-multi/by-trait.t

commit a264981ad5f9439aec2e797a9c35b55d354183b1
Author​: kyle <kyle@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Fri Nov 13 19​:05​:21 2009 +0000

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

Inline Patch
diff --git a/t/spec/S02-magicals/dollar_bang.t b/t/spec/S02-magicals/dollar_bang.t
index 3b33e06..b283493 100644
--- a/t/spec/S02-magicals/dollar_bang.t
+++ b/t/spec/S02-magicals/dollar_bang.t
@@ -40,7 +40,7 @@ ok $!, 'Dividing one by zero sets $!';
 sub incr ( $a is rw ) { $a++ };
 undefine $!;
 try { incr(19) };
-#?rakudo todo 'containers/values'
+#?rakudo todo 'RT 66588: containers/values'
 ok $!, 'Modifying a constant sets $!';
 
 try {
diff --git a/t/spec/S06-multi/by-trait.t b/t/spec/S06-multi/by-trait.t
new file mode 100644
index 0000000..45b33df
--- /dev/null
+++ b/t/spec/S06-multi/by-trait.t
@@ -0,0 +1,23 @@
+use v6;
+use Test;
+plan *;
+
+{
+    my $ro_call = 0;
+    my $rw_call = 0;
+    sub uno_mas( Int $ro       ) { $ro_call++; return 1 + $ro }
+    sub uno_mas( Int $rw is rw ) { $rw_call++; return ++$rw }
+    
+    is uno_mas(42), 43, 'multi works with constant';
+    is $ro_call, 1, 'read-only multi was called';
+
+    my $x = 99;
+    is uno_mas( $x ), 100, 'multi works with variable';
+    #?rakudo 2 todo 'RT 66588: multi dispatch by trait'
+    is $x, 100, 'variable was modified';
+    is $rw_call, 1, 'read-write multi was called';
+}
+
+done_testing;
+
+# vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Nov 13, 2009

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

@p6rt
Copy link
Author

p6rt commented Mar 9, 2010

From @moritz

now fails properly with "Cannot assign to readonly value"

@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
@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