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

Unhelpful error messages instead of DWIM when doing &&= or ?&= or ?|= or ?^= on an undefined variable in the rhs in Rakudo #2167

Closed
p6rt opened this issue Sep 14, 2010 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 14, 2010

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

Searchable as RT77864$

@p6rt
Copy link
Author

p6rt commented Sep 14, 2010

From @masak

<thundergnat> std​: my $x; $x &&= 1; say $x;
<p6eval> std : OUTPUT«ok 00​:01 118m␤»
<thundergnat> rakudo​: my $x; $x &&= 1; say $x;
<p6eval> rakudo 51e3ff​: OUTPUT«No applicable candidates found to
dispatch to for 'infix​:<&&>'. Available candidates are​:␤​:(Mu $a, Mu
$b)␤␤ in main program body at line 1␤»
* masak submits rakudobug
<masak> thundergnat++
<thundergnat> rakudo​: my $x; $x ?&= 1; say $x;
<p6eval> rakudo 51e3ff​: OUTPUT«No applicable candidates found to
dispatch to for 'infix​:<?&>'. Available candidates are​:␤​:(Any $a, Any
$b)␤␤ in main program body at line 1␤»
<thundergnat> rakudo​: my $x; $x ?|= 1; say $x;
<p6eval> rakudo 51e3ff​: OUTPUT«No applicable candidates found to
dispatch to for 'infix​:<?|>'. Available candidates are​:␤​:(Any $a, Any
$b)␤␤ in main program body at line 1␤»
<thundergnat> rakudo​: my $x; $x ?^= 1; say $x;
<p6eval> rakudo 51e3ff​: OUTPUT«No applicable candidates found to
dispatch to for 'infix​:<?^>'. Available candidates are​:␤​:(Any $a, Any
$b)␤␤ in main program body at line 1␤»

@p6rt
Copy link
Author

p6rt commented Sep 16, 2010

From @pmichaud

Now fixed in 358d728. This fix also provides the reduction [?&], [?|],
etc. forms for 0- and 1-element lists.

Assigning to moritz++ for spectest coverage.

Pm

@p6rt
Copy link
Author

p6rt commented Sep 16, 2010

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

@p6rt
Copy link
Author

p6rt commented Sep 18, 2010

From @moritz

Basic tests added to S03-operators/short-circuit.t.

19​:52 < moritz_> rakudo​: my $x; $x &&= 5; say $x
19​:52 <+p6eval> rakudo a204ba​: OUTPUT«5␤»
19​:52 < moritz_> somebody please confirm that this is wrong
...
19​:53 < jnthn> moritz_​: Looks wrong to me.

I'm glad I haven't lost my sanity over it :-)

@p6rt
Copy link
Author

p6rt commented Sep 18, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in S03-operators/short-circuit.t

commit 519bef8c25fae4227ae9676f84da410b39291357
Author​: Moritz Lenz <moritz@​faui2k3.org>
Date​: Sat Sep 18 19​:54​:10 2010 +0200

  some basic tests for RT #​77864, &&=, ||= etc. One of them fails

Inline Patch
diff --git a/S03-operators/short-circuit.t b/S03-operators/short-circuit.t
index 87d0254..a6388ef 100644
--- a/S03-operators/short-circuit.t
+++ b/S03-operators/short-circuit.t
@@ -14,7 +14,7 @@ it is closely related to || and && and //.
 
 # test cases by Andrew Savige
 
-plan 37;
+plan 39;
 
 {
     my $x = 1;
@@ -174,6 +174,17 @@ plan 37;
 # a rakudo regression
 ok (0 || 0 || 1), '0 || 0 || 1 is true';
 
+# RT #77864
+{
+    my $x;
+    $x &&= 5;
+    #?rakudo todo '77864'
+    nok $x.defined, '&&= leaves var on the right undefined';
+    my $y ||= 'moin';
+    is $y, 'moin', '||= on a fresh variable works';
+
+}
+
 done_testing;
 
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Sep 19, 2010

From @pmichaud

On Sat Sep 18 10​:55​:52 2010, moritz wrote​:

Basic tests added to S03-operators/short-circuit.t.

19​:52 < moritz_> rakudo​: my $x; $x &&= 5; say $x
19​:52 <+p6eval> rakudo a204ba​: OUTPUT«5␤»
19​:52 < moritz_> somebody please confirm that this is wrong
...
19​:53 < jnthn> moritz_​: Looks wrong to me.

Rakudo is correct here -- see S03​:3979​:

  "If you apply an assignment operator to a container containing a
  type object (which is undefined), [...] the operation is defined
  in terms of the corresponding reduction operator, where the type
  object autovivifies to the operator's identity value."

The identity value for [&&] is True, so Rakudo has this correct.

By way of comparison, consider​: "my $x; $x *= 5;" which leaves $x
with the value of 5.

Pm

@p6rt
Copy link
Author

p6rt commented Sep 19, 2010

From @pmichaud

Updated test to match spec, resolving ticket.

Pm

@p6rt
Copy link
Author

p6rt commented Sep 19, 2010

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

@p6rt p6rt closed this as completed Sep 19, 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