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

Pairs constructor :pair and :!pair do not work properly in Rakudo #865

Closed
p6rt opened this issue Apr 5, 2009 · 11 comments
Closed

Pairs constructor :pair and :!pair do not work properly in Rakudo #865

p6rt opened this issue Apr 5, 2009 · 11 comments

Comments

@p6rt
Copy link

p6rt commented Apr 5, 2009

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

Searchable as RT64478$

@p6rt
Copy link
Author

p6rt commented Apr 5, 2009

From @ilyabelikin

Ho there,

Pairs constructor changed​:

S02, L2538

  Fat arrow Adverbial pair Paren form
  ========= ============== ==========
  a => True :a
  a => False :!a

but in Rakudo, now​:

:a.perl.say
"a" => 1

:!a.perl.say
"a" => 0

I hope this one easy to fix. Thank you!

Ilya

@p6rt
Copy link
Author

p6rt commented Apr 6, 2009

@ilyabelikin - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 6, 2009

From @ilyabelikin

Argh, gmail eat one.

2009/4/7 Ð�лÑ�Ñ� <forihrd@​gmail.com>​:

Hi there,
Moritz++ and Jonathan++ help my to make patch for this bug, diffs in attach.

Ilya

2009/4/5 Ilya Belikin <perl6-bugs-followup@​perl.org>​:

# New Ticket Created by  Ilya Belikin
# Please include the string​:  [perl #​64478]
# in the subject line of all future correspondence about this issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=64478 >

Ho there,

Pairs constructor changed​:

S02, L2538

   Fat arrow           Adverbial pair  Paren form
   =========           ==============  ==========
   a => True           :a
   a => False          :!a

but in Rakudo, now​:

:a.perl.say
"a" => 1

:!a.perl.say
"a" => 0

I hope this one easy to fix. Thank you!

Ilya

@p6rt
Copy link
Author

p6rt commented Apr 6, 2009

From @ilyabelikin

Yet Another Approach

@p6rt
Copy link
Author

p6rt commented Apr 6, 2009

From @ilyabelikin

patch.diff
diff --git a/src/parser/actions.pm b/src/parser/actions.pm
index 6939aac..c198252 100644
--- a/src/parser/actions.pm
+++ b/src/parser/actions.pm
@@ -2880,7 +2880,7 @@ method colonpair($/, $key) {
 
     if $key eq 'false' {
         $pair_key := PAST::Val.new( :value(~$<identifier>) );
-        $pair_val := PAST::Val.new( :value(0), :returns('Int') );
+        $pair_val := PAST::Var.new( :name('False'), :namespace('Bool'), :scope('package') );
     }
     elsif $key eq 'value' {
         $pair_key := PAST::Val.new( :value(~$<identifier>) );
@@ -2891,7 +2891,7 @@ method colonpair($/, $key) {
             }
         }
         else {
-            $pair_val := PAST::Val.new( :value(1), :returns('Int') );
+            $pair_val := PAST::Var.new( :name('True'), :namespace('Bool'), :scope('package') );
         }
     }
     elsif $key eq 'varname' {

@p6rt
Copy link
Author

p6rt commented Apr 6, 2009

From @ilyabelikin

Hi there,
Moritz++ and Jonathan++ help my to make patch for this bug, diffs in attach.

Ilya

2009/4/5 Ilya Belikin <perl6-bugs-followup@​perl.org>​:

# New Ticket Created by  Ilya Belikin
# Please include the string​:  [perl #​64478]
# in the subject line of all future correspondence about this issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=64478 >

Ho there,

Pairs constructor changed​:

S02, L2538

   Fat arrow           Adverbial pair  Paren form
   =========           ==============  ==========
   a => True           :a
   a => False          :!a

but in Rakudo, now​:

:a.perl.say
"a" => 1

:!a.perl.say
"a" => 0

I hope this one easy to fix. Thank you!

Ilya

@p6rt
Copy link
Author

p6rt commented Apr 6, 2009

From @ilyabelikin

colonpair-tests.diff
Index: S02-builtin_data_types/pair.t
===================================================================
--- S02-builtin_data_types/pair.t	(revision 26099)
+++ S02-builtin_data_types/pair.t	(working copy)
@@ -2,7 +2,7 @@
 
 use Test;
 
-plan 99;
+plan 106;
 
 # basic Pair
 
@@ -89,6 +89,16 @@
     ok (%($pair) ~~ Hash), '%() makes creates a real Hash';
 }
 
+# colonpair
+
+is(:foo.key, 'foo', 'got the right key :foo.key');
+isa_ok(:foo.value, Bool::True, ':foo.value isa Bool::True');
+ok( :foo, ':foo is True');
+ok( :foo.value, ':foo.value is True');
+is(:!foo.key, 'foo', 'got the right key :!foo.key');
+isa_ok(:!foo.value, Bool::False, ':!foo.value isa Bool::False');
+nok( :!foo.value, ':!foo.value is False');
+
 # illustrate a bug
 
 {

@p6rt
Copy link
Author

p6rt commented Apr 7, 2009

From @moritz

Thanks, I've added the tests to the test suite (fudged for now). I can't
comment on the code fix itself, I hope that jonathan or pmichaud will
chime in.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Apr 19, 2009

From @ilyabelikin

IRC log, pmichaud answering why my patch is wrong​:

pmichaud​: it's something like this​: .value on a Pair is an lvalue
pmichaud​: so, if I have :x and :y
pmichaud​: or, more precisely, if I have
pmichaud​: my $x = :x; my $y = :y;
pmichaud​: then both $x.value and $y.value end up referring to exactly
the same PMC
pmichaud​: so that if someone ends up later doing $x.value = 3;
pmichaud​: it has the potential to also change $y.value (since they're
bound to the same PMC)
pmichaud​: so, what really needs to happen is to end up with separate
copies of Bool​::True and Bool​::False
pmichaud​: i.e., the problem is related to the difference between doing
a binding (which is what your code ends up doing) and an assignment or
using a constant
pmichaud​: (I'm trying to think of a good way to update the patch)
pmichaud​: okay, I don't have a good fix off the top of my ehad.
pmichaud​: For that reason I think perhaps we can go ahead and apply
this patch as-is
pmichaud​: but we should put a note in there that it might cause issues
with binding to True/False later.
ihrd​: aha, now I am understend
ihrd​: no. I don`t, why binding is wrong here? I can`t find out the
situations where this is broken something
ihrd​: > my $x = :x; my $y = :y; $x.value = 2; say $y.perl; say $x.perl
ihrd​: "y" => Bool​::True
ihrd​: "x" => 2
pmichaud​: yes, but Pairs are currently not doing .value correctly.
When they do, this will break.
ihrd​: ah :(

@p6rt
Copy link
Author

p6rt commented Mar 9, 2010

From @moritz

This has been fixed long since, closing ticket...

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant